From c419eb1265253bd22bfbce8110e7c8d6041447b7 Mon Sep 17 00:00:00 2001 From: Lev Khobotov Date: Mon, 13 Dec 2021 18:41:39 +0300 Subject: [PATCH] Implement external authentication --- .github/workflows/main.yml | 8 +- .../Amphasis.Azure.WebPortal.csproj | 13 +-- .../Models/CustomClaims.cs | 7 ++ Amphasis.Azure.WebPortal/Pages/Profile.cshtml | 17 ++++ .../Pages/Profile.cshtml.cs | 18 ++++ .../Pages/Shared/_Layout.cshtml | 16 +++- Amphasis.Azure.WebPortal/Pages/SignIn.cshtml | 21 +++++ .../Pages/SignIn.cshtml.cs | 80 ++++++++++++++++++ .../Pages/SimaLandGoods.cshtml.cs | 2 + Amphasis.Azure.WebPortal/Startup.cs | 72 ++++++++++++++++ .../Yandex/Models/YandexUserInfo.cs | 47 ++++++++++ .../wwwroot/external/Default.png | Bin 0 -> 5168 bytes .../wwwroot/external/MailRu.png | Bin 0 -> 20003 bytes .../wwwroot/external/Vkontakte.png | Bin 0 -> 2662 bytes .../wwwroot/external/Yandex.png | Bin 0 -> 2208 bytes Amphasis.Azure.WebPortal/wwwroot/mask.png | Bin 10707 -> 0 bytes 16 files changed, 289 insertions(+), 12 deletions(-) create mode 100644 Amphasis.Azure.WebPortal/Models/CustomClaims.cs create mode 100644 Amphasis.Azure.WebPortal/Pages/Profile.cshtml create mode 100644 Amphasis.Azure.WebPortal/Pages/Profile.cshtml.cs create mode 100644 Amphasis.Azure.WebPortal/Pages/SignIn.cshtml create mode 100644 Amphasis.Azure.WebPortal/Pages/SignIn.cshtml.cs create mode 100644 Amphasis.Azure.WebPortal/Yandex/Models/YandexUserInfo.cs create mode 100644 Amphasis.Azure.WebPortal/wwwroot/external/Default.png create mode 100644 Amphasis.Azure.WebPortal/wwwroot/external/MailRu.png create mode 100644 Amphasis.Azure.WebPortal/wwwroot/external/Vkontakte.png create mode 100644 Amphasis.Azure.WebPortal/wwwroot/external/Yandex.png delete mode 100644 Amphasis.Azure.WebPortal/wwwroot/mask.png diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4d61a67..1b216a5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,16 +3,14 @@ name: Deploy ASP.NET Core app to Azure Web App on: push: branches: [ master ] - pull_request: - branches: [ master ] env: - NUGET_USERNAME: amphasis + NUGET_USERNAME: amphasis NUGET_SOURCE: https://nuget.pkg.github.com/amphasis/index.json - DOTNET_VERSION: '3.1.403' + DOTNET_VERSION: '6.0.100' AZURE_WEBAPP_NAME: 'leff' AZURE_WEBAPP_PACKAGE_PATH: '.' - AZURE_WEBAPP_PROJECT_PATH: 'Amphasis.Azure.WebPortal' + AZURE_WEBAPP_PROJECT_PATH: 'Amphasis.Azure.WebPortal' jobs: build-and-deploy: diff --git a/Amphasis.Azure.WebPortal/Amphasis.Azure.WebPortal.csproj b/Amphasis.Azure.WebPortal/Amphasis.Azure.WebPortal.csproj index f6717b7..536f53d 100644 --- a/Amphasis.Azure.WebPortal/Amphasis.Azure.WebPortal.csproj +++ b/Amphasis.Azure.WebPortal/Amphasis.Azure.WebPortal.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net6.0 InProcess 3ad90e84-123b-437a-ad29-dd08e1e3db34 @@ -9,10 +9,13 @@ - - - - + + + + + + + diff --git a/Amphasis.Azure.WebPortal/Models/CustomClaims.cs b/Amphasis.Azure.WebPortal/Models/CustomClaims.cs new file mode 100644 index 0000000..e917a4e --- /dev/null +++ b/Amphasis.Azure.WebPortal/Models/CustomClaims.cs @@ -0,0 +1,7 @@ +namespace Amphasis.Azure.WebPortal.Models +{ + public static class CustomClaims + { + public static string UserImageUrl => "urn:amphasis:user:image"; + } +} \ No newline at end of file diff --git a/Amphasis.Azure.WebPortal/Pages/Profile.cshtml b/Amphasis.Azure.WebPortal/Pages/Profile.cshtml new file mode 100644 index 0000000..e93525f --- /dev/null +++ b/Amphasis.Azure.WebPortal/Pages/Profile.cshtml @@ -0,0 +1,17 @@ +@page +@using System.Security.Claims +@using Amphasis.Azure.WebPortal.Models +@model Amphasis.Azure.WebPortal.Pages.ProfileModel +@{ + ViewData["Title"] = "User Profile"; + var name = HttpContext.User.Identity.Name; + var email = HttpContext.User.FindFirst(ClaimTypes.Email)?.Value; + var nameIdentifier = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; + var userImageUrl = HttpContext.User.FindFirst(CustomClaims.UserImageUrl)?.Value; +} +

@ViewData["Title"]

+ +

Name: @name

+

E-Mail: @email

+

Name Identifier: @nameIdentifier

+
diff --git a/Amphasis.Azure.WebPortal/Pages/Profile.cshtml.cs b/Amphasis.Azure.WebPortal/Pages/Profile.cshtml.cs new file mode 100644 index 0000000..7731927 --- /dev/null +++ b/Amphasis.Azure.WebPortal/Pages/Profile.cshtml.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace Amphasis.Azure.WebPortal.Pages +{ + [Authorize] + public class ProfileModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/Amphasis.Azure.WebPortal/Pages/Shared/_Layout.cshtml b/Amphasis.Azure.WebPortal/Pages/Shared/_Layout.cshtml index 7bd6b92..8e52cb3 100644 --- a/Amphasis.Azure.WebPortal/Pages/Shared/_Layout.cshtml +++ b/Amphasis.Azure.WebPortal/Pages/Shared/_Layout.cshtml @@ -6,7 +6,7 @@ @ViewData["Title"] - Amphasis Web Portal - +