mirror of https://github.com/abpframework/abp.git
4 changed files with 55 additions and 18 deletions
@ -0,0 +1,36 @@ |
|||||
|
using System.Security.Claims; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.Security.Claims |
||||
|
{ |
||||
|
public class AbpClaimsIdentityService : IAbpClaimsIdentityService, ITransientDependency |
||||
|
{ |
||||
|
protected AbpClaimOptions Options { get; } |
||||
|
protected IServiceScopeFactory ServiceScopeFactory { get; } |
||||
|
|
||||
|
public AbpClaimsIdentityService( |
||||
|
IServiceScopeFactory serviceScopeFactory, |
||||
|
IOptions<AbpClaimOptions> abpClaimOptions) |
||||
|
{ |
||||
|
ServiceScopeFactory = serviceScopeFactory; |
||||
|
Options = abpClaimOptions.Value; |
||||
|
} |
||||
|
|
||||
|
public async Task AddClaimsAsync(ClaimsIdentity identity) |
||||
|
{ |
||||
|
using (var scope = ServiceScopeFactory.CreateScope()) |
||||
|
{ |
||||
|
var context = new ClaimsIdentityContext(identity, scope.ServiceProvider); |
||||
|
|
||||
|
foreach (var contributorType in Options.ClaimsIdentityContributors) |
||||
|
{ |
||||
|
var contributor = (IClaimsIdentityContributor) scope.ServiceProvider.GetRequiredService(contributorType); |
||||
|
await contributor.AddClaimsAsync(context); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using System.Security.Claims; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.Security.Claims |
||||
|
{ |
||||
|
public interface IAbpClaimsIdentityService |
||||
|
{ |
||||
|
Task AddClaimsAsync(ClaimsIdentity identity); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue