From 32d8dc0c4eadb1bc2519a7bd2e8c463fdc308da5 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sun, 14 Nov 2021 00:21:13 +0200 Subject: [PATCH] IdentityAuthenticationHandler null claims fix --- .../IdentityAuthenticationHandler.cs | 15 ++++++++++----- .../NDB.Security.Authentication.Identity.csproj | 2 +- Notes.txt | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/NDB.Security.Authentication.Identity/IdentityAuthenticationHandler.cs b/NDB.Security.Authentication.Identity/IdentityAuthenticationHandler.cs index e633b55..b0c7f6a 100644 --- a/NDB.Security.Authentication.Identity/IdentityAuthenticationHandler.cs +++ b/NDB.Security.Authentication.Identity/IdentityAuthenticationHandler.cs @@ -76,13 +76,18 @@ namespace NDB.Security.Authentication.Identity { { ClaimTypes.NameIdentifier, tokenCore.UserId.ToString() }, { ClaimTypes.Name, tokenCore.UserName }, - { Constants.ClaimTypes.UserName, tokenCore.UserName }, - { Constants.ClaimTypes.FirstName, tokenCore.FirstName }, - { Constants.ClaimTypes.LastName, tokenCore.LastName }, - { Constants.ClaimTypes.ProfilePictureUrl, tokenCore.ProfilePictureUrl }, - { ClaimTypes.Email, tokenCore.Email } + { Constants.ClaimTypes.UserName, tokenCore.UserName } }; + if (tokenCore.FirstName != null) + claimCollection.Add(Constants.ClaimTypes.FirstName, tokenCore.FirstName); + if (tokenCore.LastName != null) + claimCollection.Add(Constants.ClaimTypes.LastName, tokenCore.LastName); + if (tokenCore.ProfilePictureUrl != null) + claimCollection.Add(Constants.ClaimTypes.ProfilePictureUrl, tokenCore.ProfilePictureUrl); + if (tokenCore.Email != null) + claimCollection.Add(ClaimTypes.Email, tokenCore.Email); + if (tokenCore.Claims != null && tokenCore.Claims.Any()) { foreach (var claim in tokenCore.Claims) diff --git a/NDB.Security.Authentication.Identity/NDB.Security.Authentication.Identity.csproj b/NDB.Security.Authentication.Identity/NDB.Security.Authentication.Identity.csproj index a4c3c56..c12a01f 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.5 + 1.0.6 diff --git a/Notes.txt b/Notes.txt index 4e50d0f..dec157c 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.5.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget +dotnet nuget push NDB.Security.Authentication.Identity.1.0.6.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget dotnet nuget push NDB.Extensions.Caching.1.0.1.nupkg -k ***REMOVED*** -s http://stawebsrv:8081/NuGetServer/nuget ####################################################################################################################################################### \ No newline at end of file