mirror of https://github.com/abpframework/abp.git
11 changed files with 158 additions and 42 deletions
@ -0,0 +1,14 @@ |
|||
using Microsoft.AspNetCore.Http; |
|||
using OpenIddict.Server; |
|||
using OpenIddict.Server.AspNetCore; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public static class AbpOpenIddictHttpContextExtensions |
|||
{ |
|||
public static OpenIddictServerTransaction GetOpenIddictServerTransaction(this HttpContext context) |
|||
{ |
|||
Check.NotNull(context, nameof(context)); |
|||
return context.Features.Get<OpenIddictServerAspNetCoreFeature>()?.Transaction; |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Net; |
|||
using OpenIddict.Abstractions; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.OpenIddict; |
|||
|
|||
public class AbpOpenIddictRequestHelper : ITransientDependency |
|||
{ |
|||
public virtual Task<OpenIddictRequest> GetFromReturnUrlAsync(string returnUrl) |
|||
{ |
|||
if (!returnUrl.IsNullOrWhiteSpace()) |
|||
{ |
|||
var qm = returnUrl.IndexOf("?", StringComparison.Ordinal); |
|||
if (qm > 0) |
|||
{ |
|||
return Task.FromResult(new OpenIddictRequest(returnUrl.Substring(qm + 1) |
|||
.Split("&") |
|||
.Select(x => |
|||
x.Split("=").Length == 2 |
|||
? new KeyValuePair<string, string>(x.Split("=")[0], WebUtility.UrlDecode(x.Split("=")[1])) |
|||
: new KeyValuePair<string, string>(null, null)) |
|||
.Where(x => x.Key != null))); |
|||
} |
|||
} |
|||
|
|||
return Task.FromResult<OpenIddictRequest>(null); |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
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())); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace Volo.Abp.OpenIddict.ExtensionGrantTypes; |
|||
|
|||
public class AbpOpenIddictExtensionGrantsOptions |
|||
{ |
|||
public Dictionary<string, IExtensionGrant> Grants { get; } |
|||
|
|||
public AbpOpenIddictExtensionGrantsOptions() |
|||
{ |
|||
Grants = new Dictionary<string, IExtensionGrant>(); |
|||
} |
|||
|
|||
public TExtensionGrantType Find<TExtensionGrantType>(string name) |
|||
where TExtensionGrantType : IExtensionGrant |
|||
{ |
|||
return (TExtensionGrantType)Grants.FirstOrDefault(x => x.Key == name && x.Value is TExtensionGrantType).Value; |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using Microsoft.AspNetCore.Http; |
|||
using OpenIddict.Abstractions; |
|||
|
|||
namespace Volo.Abp.OpenIddict.ExtensionGrantTypes; |
|||
|
|||
public class ExtensionGrantContext |
|||
{ |
|||
public HttpContext HttpContext { get; } |
|||
|
|||
public OpenIddictRequest Request { get; } |
|||
|
|||
public ExtensionGrantContext(HttpContext httpContext, OpenIddictRequest request) |
|||
{ |
|||
HttpContext = httpContext; |
|||
Request = request; |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
|
|||
namespace Volo.Abp.OpenIddict.ExtensionGrantTypes; |
|||
|
|||
public interface IExtensionGrant |
|||
{ |
|||
string Name { get; } |
|||
|
|||
Task<IActionResult> HandleAsync(ExtensionGrantContext context); |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
namespace Volo.Abp.OpenIddict.ExtensionGrantTypes; |
|||
|
|||
public interface ITokenExtensionGrant : IExtensionGrant |
|||
{ |
|||
|
|||
} |
|||
Loading…
Reference in new issue