2019-07-01 05:39:25 +02:00
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
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
|
|
|
|
{
|
2019-08-29 09:25:16 +02:00
|
|
|
public class LogoutEventHandler : BaseOpenIdGrantHandler<OpenIddictServerEvents.HandleLogoutRequest>
|
2019-07-01 05:39:25 +02:00
|
|
|
{
|
2019-08-29 09:25:16 +02:00
|
|
|
public LogoutEventHandler(
|
|
|
|
OpenIddictApplicationManager<BTCPayOpenIdClient> applicationManager,
|
|
|
|
OpenIddictAuthorizationManager<BTCPayOpenIdAuthorization> authorizationManager,
|
|
|
|
SignInManager<ApplicationUser> signInManager, IOptions<IdentityOptions> identityOptions) : base(
|
|
|
|
applicationManager, authorizationManager,
|
|
|
|
signInManager, identityOptions)
|
2019-07-01 05:39:25 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-29 09:25:16 +02:00
|
|
|
public override async Task<OpenIddictServerEventState> HandleAsync(
|
|
|
|
OpenIddictServerEvents.HandleLogoutRequest notification)
|
2019-07-01 05:39:25 +02:00
|
|
|
{
|
|
|
|
// Ask ASP.NET Core Identity to delete the local and external cookies created
|
|
|
|
// when the user agent is redirected from the external identity provider
|
|
|
|
// after a successful authentication flow (e.g Google or Facebook).
|
|
|
|
await _signInManager.SignOutAsync();
|
|
|
|
|
|
|
|
// Returning a SignOutResult will ask OpenIddict to redirect the user agent
|
|
|
|
// to the post_logout_redirect_uri specified by the client application.
|
|
|
|
await notification.Context.HttpContext.SignOutAsync(OpenIddictServerDefaults.AuthenticationScheme);
|
|
|
|
notification.Context.HandleResponse();
|
|
|
|
return OpenIddictServerEventState.Handled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|