mirror of https://github.com/abpframework/abp.git
19 changed files with 99 additions and 97 deletions
@ -1,32 +0,0 @@ |
|||
using System.Linq; |
|||
using System.Security.Claims; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public class AbpOpenIddictClaimDestinationsManager : ISingletonDependency |
|||
{ |
|||
protected IServiceScopeFactory ServiceScopeFactory { get; } |
|||
protected IOptions<AbpOpenIddictClaimDestinationsOptions> Options { get; } |
|||
|
|||
public AbpOpenIddictClaimDestinationsManager(IServiceScopeFactory serviceScopeFactory, IOptions<AbpOpenIddictClaimDestinationsOptions> options) |
|||
{ |
|||
ServiceScopeFactory = serviceScopeFactory; |
|||
Options = options; |
|||
} |
|||
|
|||
public virtual async Task SetAsync(ClaimsPrincipal principal) |
|||
{ |
|||
using (var scope = ServiceScopeFactory.CreateScope()) |
|||
{ |
|||
foreach (var providerType in Options.Value.ClaimDestinationsProvider) |
|||
{ |
|||
var provider = (IAbpOpenIddictClaimDestinationsProvider)scope.ServiceProvider.GetRequiredService(providerType); |
|||
await provider.SetDestinationsAsync(new AbpOpenIddictClaimDestinationsProviderContext(scope.ServiceProvider, principal, principal.Claims.ToArray())); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
using Volo.Abp.Collections; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public class AbpOpenIddictClaimDestinationsOptions |
|||
{ |
|||
public ITypeList<IAbpOpenIddictClaimDestinationsProvider> ClaimDestinationsProvider { get; } |
|||
|
|||
public AbpOpenIddictClaimDestinationsOptions() |
|||
{ |
|||
ClaimDestinationsProvider = new TypeList<IAbpOpenIddictClaimDestinationsProvider>(); |
|||
} |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
using System; |
|||
using System.Security.Claims; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public class AbpOpenIddictClaimDestinationsProviderContext |
|||
{ |
|||
public IServiceProvider ScopeServiceProvider { get; } |
|||
|
|||
public ClaimsPrincipal Principal{ get;} |
|||
|
|||
public Claim[] Claims { get; } |
|||
|
|||
public AbpOpenIddictClaimDestinationsProviderContext(IServiceProvider scopeServiceProvider, ClaimsPrincipal principal, Claim[] claims) |
|||
{ |
|||
ScopeServiceProvider = scopeServiceProvider; |
|||
Principal = principal; |
|||
Claims = claims; |
|||
} |
|||
} |
|||
@ -1,8 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public interface IAbpOpenIddictClaimDestinationsProvider |
|||
{ |
|||
Task SetDestinationsAsync(AbpOpenIddictClaimDestinationsProviderContext context); |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System; |
|||
using System.Security.Claims; |
|||
using OpenIddict.Abstractions; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public class AbpOpenIddictClaimsPrincipalHandlerContext |
|||
{ |
|||
public IServiceProvider ScopeServiceProvider { get; } |
|||
|
|||
public OpenIddictRequest OpenIddictRequest { get; } |
|||
|
|||
public ClaimsPrincipal Principal { get;} |
|||
|
|||
public AbpOpenIddictClaimsPrincipalHandlerContext(IServiceProvider scopeServiceProvider, OpenIddictRequest openIddictRequest, ClaimsPrincipal principal) |
|||
{ |
|||
ScopeServiceProvider = scopeServiceProvider; |
|||
OpenIddictRequest = openIddictRequest; |
|||
Principal = principal; |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using System.Security.Claims; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using OpenIddict.Abstractions; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public class AbpOpenIddictClaimsPrincipalManager : ISingletonDependency |
|||
{ |
|||
protected IServiceScopeFactory ServiceScopeFactory { get; } |
|||
protected IOptions<AbpOpenIddictClaimsPrincipalOptions> Options { get; } |
|||
|
|||
public AbpOpenIddictClaimsPrincipalManager(IServiceScopeFactory serviceScopeFactory, IOptions<AbpOpenIddictClaimsPrincipalOptions> options) |
|||
{ |
|||
ServiceScopeFactory = serviceScopeFactory; |
|||
Options = options; |
|||
} |
|||
|
|||
public virtual async Task HandleAsync(OpenIddictRequest openIddictRequest, ClaimsPrincipal principal) |
|||
{ |
|||
using (var scope = ServiceScopeFactory.CreateScope()) |
|||
{ |
|||
foreach (var providerType in Options.Value.ClaimsPrincipalHandlers) |
|||
{ |
|||
var provider = (IAbpOpenIddictClaimsPrincipalHandler)scope.ServiceProvider.GetRequiredService(providerType); |
|||
await provider.HandleAsync(new AbpOpenIddictClaimsPrincipalHandlerContext(scope.ServiceProvider, openIddictRequest, principal)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.Collections; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public class AbpOpenIddictClaimsPrincipalOptions |
|||
{ |
|||
public ITypeList<IAbpOpenIddictClaimsPrincipalHandler> ClaimsPrincipalHandlers { get; } |
|||
|
|||
public AbpOpenIddictClaimsPrincipalOptions() |
|||
{ |
|||
ClaimsPrincipalHandlers = new TypeList<IAbpOpenIddictClaimsPrincipalHandler>(); |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public interface IAbpOpenIddictClaimsPrincipalHandler |
|||
{ |
|||
Task HandleAsync(AbpOpenIddictClaimsPrincipalHandlerContext context); |
|||
} |
|||
Loading…
Reference in new issue