From 67a9b643d887bae212e02391b0f3fab8b010d661 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Tue, 29 Jun 2021 10:01:18 +0300 Subject: [PATCH] NDB.Security.Authentication.Identity - guest user claim --- NDB.Extensions.Caching/NDB.Extensions.Caching.csproj | 1 + .../Constants/ClaimTypes.cs | 8 ++++++++ .../IdentityAuthenticationHandler.cs | 5 +++-- .../NDB.Security.Authentication.Identity.csproj | 2 +- Notes.txt | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 NDB.Security.Authentication.Identity/Constants/ClaimTypes.cs diff --git a/NDB.Extensions.Caching/NDB.Extensions.Caching.csproj b/NDB.Extensions.Caching/NDB.Extensions.Caching.csproj index c99ec21..c358d78 100644 --- a/NDB.Extensions.Caching/NDB.Extensions.Caching.csproj +++ b/NDB.Extensions.Caching/NDB.Extensions.Caching.csproj @@ -6,6 +6,7 @@ https://dev.azure.com/tstanciu94/NDB https://dev.azure.com/tstanciu94/NDB Git + NDB Cache diff --git a/NDB.Security.Authentication.Identity/Constants/ClaimTypes.cs b/NDB.Security.Authentication.Identity/Constants/ClaimTypes.cs new file mode 100644 index 0000000..8255fa4 --- /dev/null +++ b/NDB.Security.Authentication.Identity/Constants/ClaimTypes.cs @@ -0,0 +1,8 @@ +namespace NDB.Security.Authentication.Identity.Constants +{ + public struct ClaimTypes + { + public const string + IsGuestUser = "IsGuestUser"; + } +} diff --git a/NDB.Security.Authentication.Identity/IdentityAuthenticationHandler.cs b/NDB.Security.Authentication.Identity/IdentityAuthenticationHandler.cs index cc5570a..d28fbbf 100644 --- a/NDB.Security.Authentication.Identity/IdentityAuthenticationHandler.cs +++ b/NDB.Security.Authentication.Identity/IdentityAuthenticationHandler.cs @@ -30,7 +30,7 @@ namespace NDB.Security.Authentication.Identity var authenticateAsGuest = _authenticationOptions.AuthenticateAsGuest?.Invoke(Request) ?? false; if (authenticateAsGuest) { - var guestTicket = GetAuthenticationTicket(new User() { UserId = _authenticationOptions.GuestUserId, UserName = _authenticationOptions.GuestUserName }); + var guestTicket = GetAuthenticationTicket(new User() { UserId = _authenticationOptions.GuestUserId, UserName = _authenticationOptions.GuestUserName }, true); return AuthenticateResult.Success(guestTicket); } @@ -56,11 +56,12 @@ namespace NDB.Security.Authentication.Identity return AuthenticateResult.Success(ticket); } - private AuthenticationTicket GetAuthenticationTicket(User user) + private AuthenticationTicket GetAuthenticationTicket(User user, bool isGuest = false) { var claims = new[] { new Claim(ClaimTypes.NameIdentifier, user.UserId.ToString()), new Claim(ClaimTypes.Name, user.UserName), + new Claim(Constants.ClaimTypes.IsGuestUser, isGuest.ToString()) }; var identity = new ClaimsIdentity(claims, Scheme.Name); diff --git a/NDB.Security.Authentication.Identity/NDB.Security.Authentication.Identity.csproj b/NDB.Security.Authentication.Identity/NDB.Security.Authentication.Identity.csproj index 6b099e6..e9e4654 100644 --- a/NDB.Security.Authentication.Identity/NDB.Security.Authentication.Identity.csproj +++ b/NDB.Security.Authentication.Identity/NDB.Security.Authentication.Identity.csproj @@ -7,7 +7,7 @@ https://dev.azure.com/tstanciu94/NDB Git NDB Authentication Identity - 1.0.2 + 1.0.3 diff --git a/Notes.txt b/Notes.txt index 3135542..25c392a 100644 --- a/Notes.txt +++ b/Notes.txt @@ -22,7 +22,7 @@ dotnet nuget push NDB.Extensions.Swagger.1.0.2.nupkg -k ***REMOVED*** -s http:// dotnet nuget push NDB.Extensions.Http.1.0.0.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget -dotnet nuget push NDB.Security.Authentication.Identity.1.0.2.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget +dotnet nuget push NDB.Security.Authentication.Identity.1.0.3.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget dotnet nuget push NDB.Extensions.Caching.1.0.0.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget ####################################################################################################################################################### \ No newline at end of file