using System.Threading.Tasks; using AspNet.Security.OpenIdConnect.Primitives; using BTCPayServer.Authentication.OpenId.Models; using BTCPayServer.Models; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Options; using OpenIddict.Core; using OpenIddict.Server; namespace BTCPayServer.Authentication.OpenId { public abstract class BaseOpenIdGrantHandler : IOpenIddictServerEventHandler where T : class, IOpenIddictServerEvent { private readonly OpenIddictApplicationManager _applicationManager; private readonly OpenIddictAuthorizationManager _authorizationManager; protected readonly SignInManager _signInManager; protected readonly IOptions _identityOptions; protected BaseOpenIdGrantHandler( OpenIddictApplicationManager applicationManager, OpenIddictAuthorizationManager authorizationManager, SignInManager signInManager, IOptions identityOptions) { _applicationManager = applicationManager; _authorizationManager = authorizationManager; _signInManager = signInManager; _identityOptions = identityOptions; } protected async Task CreateTicketAsync( OpenIdConnectRequest request, ApplicationUser user, AuthenticationProperties properties = null) { return await OpenIdExtensions.CreateAuthenticationTicket(_applicationManager, _authorizationManager, _identityOptions.Value, _signInManager, request, user, properties); } public abstract Task HandleAsync(T notification); } }