|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security.Claims;
|
|
|
|
|
using IdentityModel;
|
|
|
|
|
using IdentityServer4.Services;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Volo.Abp.Security.Claims;
|
|
|
|
@ -9,6 +10,16 @@ namespace Volo.Abp.IdentityServer
|
|
|
|
|
{
|
|
|
|
|
public class AbpClaimsService : DefaultClaimsService
|
|
|
|
|
{
|
|
|
|
|
private static readonly string[] AdditionalOptionalClaimNames =
|
|
|
|
|
{
|
|
|
|
|
AbpClaimTypes.TenantId,
|
|
|
|
|
AbpClaimTypes.Name,
|
|
|
|
|
AbpClaimTypes.SurName,
|
|
|
|
|
JwtClaimTypes.PreferredUserName,
|
|
|
|
|
JwtClaimTypes.GivenName,
|
|
|
|
|
JwtClaimTypes.FamilyName,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public AbpClaimsService(IProfileService profile, ILogger<DefaultClaimsService> logger)
|
|
|
|
|
: base(profile, logger)
|
|
|
|
|
{
|
|
|
|
@ -16,13 +27,20 @@ namespace Volo.Abp.IdentityServer
|
|
|
|
|
|
|
|
|
|
protected override IEnumerable<Claim> GetOptionalClaims(ClaimsPrincipal subject)
|
|
|
|
|
{
|
|
|
|
|
var tenantClaim = subject.FindFirst(AbpClaimTypes.TenantId);
|
|
|
|
|
if (tenantClaim == null)
|
|
|
|
|
return base.GetOptionalClaims(subject)
|
|
|
|
|
.Union(GetAdditionalOptionalClaims(subject));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual IEnumerable<Claim> GetAdditionalOptionalClaims(ClaimsPrincipal subject)
|
|
|
|
|
{
|
|
|
|
|
foreach (var claimName in AdditionalOptionalClaimNames)
|
|
|
|
|
{
|
|
|
|
|
return base.GetOptionalClaims(subject);
|
|
|
|
|
var claim = subject.FindFirst(claimName);
|
|
|
|
|
if (claim != null)
|
|
|
|
|
{
|
|
|
|
|
yield return claim;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.GetOptionalClaims(subject).Union(new[] { tenantClaim });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|