2019-07-01 05:39:25 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using AspNet.Security.OpenIdConnect.Primitives;
|
2019-08-30 00:24:42 +09:00
|
|
|
using BTCPayServer.Data;
|
2019-07-01 05:39:25 +02:00
|
|
|
using BTCPayServer.Models;
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
using Microsoft.Extensions.Options;
|
2019-08-29 09:25:16 +02:00
|
|
|
using OpenIddict.Core;
|
2019-07-01 05:39:25 +02:00
|
|
|
using OpenIddict.Server;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Authentication.OpenId
|
|
|
|
{
|
|
|
|
public abstract class BaseOpenIdGrantHandler<T> : IOpenIddictServerEventHandler<T>
|
|
|
|
where T : class, IOpenIddictServerEvent
|
|
|
|
{
|
2019-08-29 09:25:16 +02:00
|
|
|
private readonly OpenIddictApplicationManager<BTCPayOpenIdClient> _applicationManager;
|
|
|
|
private readonly OpenIddictAuthorizationManager<BTCPayOpenIdAuthorization> _authorizationManager;
|
2019-07-01 05:39:25 +02:00
|
|
|
protected readonly SignInManager<ApplicationUser> _signInManager;
|
|
|
|
protected readonly IOptions<IdentityOptions> _identityOptions;
|
|
|
|
|
2019-08-29 09:25:16 +02:00
|
|
|
protected BaseOpenIdGrantHandler(
|
|
|
|
OpenIddictApplicationManager<BTCPayOpenIdClient> applicationManager,
|
|
|
|
OpenIddictAuthorizationManager<BTCPayOpenIdAuthorization> authorizationManager,
|
|
|
|
SignInManager<ApplicationUser> signInManager,
|
2019-07-01 05:39:25 +02:00
|
|
|
IOptions<IdentityOptions> identityOptions)
|
|
|
|
{
|
2019-08-29 09:25:16 +02:00
|
|
|
_applicationManager = applicationManager;
|
|
|
|
_authorizationManager = authorizationManager;
|
2019-07-01 05:39:25 +02:00
|
|
|
_signInManager = signInManager;
|
|
|
|
_identityOptions = identityOptions;
|
|
|
|
}
|
|
|
|
|
2019-08-29 09:25:16 +02:00
|
|
|
|
2019-07-01 05:39:25 +02:00
|
|
|
protected async Task<AuthenticationTicket> CreateTicketAsync(
|
|
|
|
OpenIdConnectRequest request, ApplicationUser user,
|
|
|
|
AuthenticationProperties properties = null)
|
|
|
|
{
|
2019-08-29 09:25:16 +02:00
|
|
|
return await OpenIdExtensions.CreateAuthenticationTicket(_applicationManager, _authorizationManager,
|
|
|
|
_identityOptions.Value, _signInManager, request, user, properties);
|
2019-07-01 05:39:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public abstract Task<OpenIddictServerEventState> HandleAsync(T notification);
|
|
|
|
}
|
|
|
|
}
|