Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AbpClaimsServiceOptions #7998

Merged
merged 3 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
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,
Expand All @@ -20,20 +23,21 @@ public class AbpClaimsService : DefaultClaimsService
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)
Expand All @@ -52,4 +56,4 @@ protected virtual IEnumerable<Claim> GetAdditionalOptionalClaims(ClaimsPrincipal
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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;
Expand All @@ -19,6 +18,7 @@
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;

Expand Down Expand Up @@ -54,6 +54,14 @@ public override void ConfigureServices(ServiceConfigurationContext context)
options.EtoMappings.Add<IdentityResource, IdentityResourceEto>(typeof(AbpIdentityServerDomainModule));
});

Configure<AbpClaimsServiceOptions>(options =>
{
options.RequestedClaims.AddRange(new []{
AbpClaimTypes.TenantId,
AbpClaimTypes.EditionId
});
});

AddIdentityServer(context.Services);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class AbpProfileService : ProfileService<IdentityUser>
}

[UnitOfWork]
public async override Task GetProfileDataAsync(ProfileDataRequestContext context)
public override async Task GetProfileDataAsync(ProfileDataRequestContext context)
{
using (CurrentTenant.Change(context.Subject.FindTenantId()))
{
Expand All @@ -33,7 +33,7 @@ public async override Task GetProfileDataAsync(ProfileDataRequestContext context
}

[UnitOfWork]
public async override Task IsActiveAsync(IsActiveContext context)
public override async Task IsActiveAsync(IsActiveContext context)
{
using (CurrentTenant.Change(context.Subject.FindTenantId()))
{
Expand Down