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 IdentityModel;
using IdentityServer4.Services; using IdentityServer4.Services;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp.Security.Claims; using Volo.Abp.Security.Claims;
namespace Volo.Abp.IdentityServer namespace Volo.Abp.IdentityServer
{ {
public class AbpClaimsService : DefaultClaimsService public class AbpClaimsService : DefaultClaimsService
{ {
protected readonly AbpClaimsServiceOptions Options;
private static readonly string[] AdditionalOptionalClaimNames = private static readonly string[] AdditionalOptionalClaimNames =
{ {
AbpClaimTypes.TenantId, AbpClaimTypes.TenantId,
@ -20,20 +23,21 @@ namespace Volo.Abp.IdentityServer
JwtClaimTypes.FamilyName, JwtClaimTypes.FamilyName,
}; };
public AbpClaimsService(IProfileService profile, ILogger<DefaultClaimsService> logger) public AbpClaimsService(
IProfileService profile,
ILogger<DefaultClaimsService> logger,
IOptions<AbpClaimsServiceOptions> options)
: base(profile, logger) : base(profile, logger)
{ {
Options = options.Value;
} }
protected override IEnumerable<string> FilterRequestedClaimTypes(IEnumerable<string> claimTypes) protected override IEnumerable<string> FilterRequestedClaimTypes(IEnumerable<string> claimTypes)
{ {
return base.FilterRequestedClaimTypes(claimTypes) return base.FilterRequestedClaimTypes(claimTypes)
.Union(new []{ .Union(Options.RequestedClaims);
AbpClaimTypes.TenantId,
AbpClaimTypes.EditionId
});
} }
protected override IEnumerable<Claim> GetOptionalClaims(ClaimsPrincipal subject) protected override IEnumerable<Claim> GetOptionalClaims(ClaimsPrincipal subject)
{ {
return base.GetOptionalClaims(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.Identity;
using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.AspNetIdentity; using Volo.Abp.IdentityServer.AspNetIdentity;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.Clients; using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.Devices; using Volo.Abp.IdentityServer.Devices;
using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.IdentityServer.IdentityResources;
@ -19,6 +18,7 @@ using Volo.Abp.Modularity;
using Volo.Abp.ObjectExtending; using Volo.Abp.ObjectExtending;
using Volo.Abp.ObjectExtending.Modularity; using Volo.Abp.ObjectExtending.Modularity;
using Volo.Abp.Security; using Volo.Abp.Security;
using Volo.Abp.Security.Claims;
using Volo.Abp.Validation; using Volo.Abp.Validation;
using Volo.Abp.Threading; using Volo.Abp.Threading;
@ -54,6 +54,14 @@ namespace Volo.Abp.IdentityServer
options.EtoMappings.Add<IdentityResource, IdentityResourceEto>(typeof(AbpIdentityServerDomainModule)); options.EtoMappings.Add<IdentityResource, IdentityResourceEto>(typeof(AbpIdentityServerDomainModule));
}); });
Configure<AbpClaimsServiceOptions>(options =>
{
options.RequestedClaims.AddRange(new []{
AbpClaimTypes.TenantId,
AbpClaimTypes.EditionId
});
});
AddIdentityServer(context.Services); 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] [UnitOfWork]
public async override Task GetProfileDataAsync(ProfileDataRequestContext context) public override async Task GetProfileDataAsync(ProfileDataRequestContext context)
{ {
using (CurrentTenant.Change(context.Subject.FindTenantId())) using (CurrentTenant.Change(context.Subject.FindTenantId()))
{ {
@ -33,7 +33,7 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity
} }
[UnitOfWork] [UnitOfWork]
public async override Task IsActiveAsync(IsActiveContext context) public override async Task IsActiveAsync(IsActiveContext context)
{ {
using (CurrentTenant.Change(context.Subject.FindTenantId())) using (CurrentTenant.Change(context.Subject.FindTenantId()))
{ {

Loading…
Cancel
Save