Skip to content

Commit

Permalink
Add UniqueName claim to the iidentity.
Browse files Browse the repository at this point in the history
  • Loading branch information
maliming committed Dec 23, 2021
1 parent 6006f19 commit 1f3c7bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using IdentityServer4.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.JsonWebTokens;
using Volo.Abp.Security.Claims;

namespace Volo.Abp.IdentityServer
Expand All @@ -20,6 +21,7 @@ public class AbpClaimsService : DefaultClaimsService
AbpClaimTypes.ImpersonatorUserId,
AbpClaimTypes.Name,
AbpClaimTypes.SurName,
JwtRegisteredClaimNames.UniqueName,
JwtClaimTypes.PreferredUserName,
JwtClaimTypes.GivenName,
JwtClaimTypes.FamilyName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using IdentityModel;
using Microsoft.AspNetCore.Identity;
using Microsoft.IdentityModel.JsonWebTokens;
using Volo.Abp.DependencyInjection;
using IdentityUser = Volo.Abp.Identity.IdentityUser;

Expand Down Expand Up @@ -41,6 +42,10 @@ public async Task<ClaimsPrincipal> CreateAsync(TUser user)
{
identity.RemoveClaim(usernameClaim);
identity.AddIfNotContains(new Claim(JwtClaimTypes.PreferredUserName, username));

//https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/1627
//https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/05e02b5e0383be40e45c667c12f6667d38e33fcc/src/System.IdentityModel.Tokens.Jwt/ClaimTypeMapping.cs#L52
identity.AddIfNotContains(new Claim(JwtRegisteredClaimNames.UniqueName, username));
}

if (!identity.HasClaim(x => x.Type == JwtClaimTypes.Name))
Expand Down

0 comments on commit 1f3c7bf

Please sign in to comment.