Browse Source

Merge pull request #7998 from abpframework/liangshiwei/claims

Added AbpClaimsServiceOptions
pull/8001/head
maliming 6 years ago
committed by GitHub
parent
commit
7b0bd7f256
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsService.cs
  2. 14
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsServiceOptions.cs
  3. 10
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs
  4. 4
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpProfileService.cs

18
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsService.cs

@ -4,12 +4,15 @@ using System.Security.Claims;
using IdentityModel;
using IdentityServer4.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp.Security.Claims;
namespace Volo.Abp.IdentityServer
{
public class AbpClaimsService : DefaultClaimsService
{
protected readonly AbpClaimsServiceOptions Options;
private static readonly string[] AdditionalOptionalClaimNames =
{
AbpClaimTypes.TenantId,
@ -20,20 +23,21 @@ namespace Volo.Abp.IdentityServer
JwtClaimTypes.FamilyName,
};
public AbpClaimsService(IProfileService profile, ILogger<DefaultClaimsService> logger)
public AbpClaimsService(
IProfileService profile,
ILogger<DefaultClaimsService> logger,
IOptions<AbpClaimsServiceOptions> options)
: base(profile, logger)
{
Options = options.Value;
}
protected override IEnumerable<string> FilterRequestedClaimTypes(IEnumerable<string> claimTypes)
{
return base.FilterRequestedClaimTypes(claimTypes)
.Union(new []{
AbpClaimTypes.TenantId,
AbpClaimTypes.EditionId
});
.Union(Options.RequestedClaims);
}
protected override IEnumerable<Claim> GetOptionalClaims(ClaimsPrincipal subject)
{
return base.GetOptionalClaims(subject)
@ -52,4 +56,4 @@ namespace Volo.Abp.IdentityServer
}
}
}
}
}

14
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsServiceOptions.cs

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace Volo.Abp.IdentityServer
{
public class AbpClaimsServiceOptions
{
public List<string> RequestedClaims { get; }
public AbpClaimsServiceOptions()
{
RequestedClaims = new List<string>();
}
}
}

10
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs

@ -10,7 +10,6 @@ using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.Identity;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.AspNetIdentity;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Devices;
using Volo.Abp.IdentityServer.IdentityResources;
@ -19,6 +18,7 @@ using Volo.Abp.Modularity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.ObjectExtending.Modularity;
using Volo.Abp.Security;
using Volo.Abp.Security.Claims;
using Volo.Abp.Validation;
using Volo.Abp.Threading;
@ -54,6 +54,14 @@ namespace Volo.Abp.IdentityServer
options.EtoMappings.Add<IdentityResource, IdentityResourceEto>(typeof(AbpIdentityServerDomainModule));
});
Configure<AbpClaimsServiceOptions>(options =>
{
options.RequestedClaims.AddRange(new []{
AbpClaimTypes.TenantId,
AbpClaimTypes.EditionId
});
});
AddIdentityServer(context.Services);
}

4
modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpProfileService.cs

@ -24,7 +24,7 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
}
[UnitOfWork]
public async override Task GetProfileDataAsync(ProfileDataRequestContext context)
public override async Task GetProfileDataAsync(ProfileDataRequestContext context)
{
using (CurrentTenant.Change(context.Subject.FindTenantId()))
{
@ -33,7 +33,7 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
}
[UnitOfWork]
public async override Task IsActiveAsync(IsActiveContext context)
public override async Task IsActiveAsync(IsActiveContext context)
{
using (CurrentTenant.Change(context.Subject.FindTenantId()))
{

Loading…
Cancel
Save