diff --git a/OpenIdDict.Server/Authorisation/OpenIdDictEvents.cs b/OpenIdDict.Server/Authorisation/OpenIdDictEvents.cs index 82c34ce..dd5c663 100644 --- a/OpenIdDict.Server/Authorisation/OpenIdDictEvents.cs +++ b/OpenIdDict.Server/Authorisation/OpenIdDictEvents.cs @@ -112,6 +112,31 @@ internal static class OpenIdDictEvents // Another plus, the API controllers can retrieve them from the ClaimsPrincipal instance. identity.SetDestinations(_ => new[] { OpenIddictConstants.Destinations.AccessToken }); }; + + /// + /// Validation of `/logout` requests + /// + internal static Func ValidateLogoutRequestFunc(AppSettings.AuthCredentialsSettings authSettings) => + context => + { + ArgumentNullException.ThrowIfNull(context); + + if (string.IsNullOrEmpty(context.PostLogoutRedirectUri)) + return default; + + // Optionally, can validate the `PostLogoutRedirectUri` + return default; + }; + + /// + /// Handling of `/logout` requests + /// + internal static Func HandleLogoutRequestFunc(AppSettings.AuthCredentialsSettings authSettings) => + context => + { + context.SignOut(); + return default; + }; /// /// Resolving mandatory email from a relevant mapped claim diff --git a/OpenIdDict.Server/Configuration/AddAndConfigureAuthorisation.cs b/OpenIdDict.Server/Configuration/AddAndConfigureAuthorisation.cs index f51d64e..905d968 100644 --- a/OpenIdDict.Server/Configuration/AddAndConfigureAuthorisation.cs +++ b/OpenIdDict.Server/Configuration/AddAndConfigureAuthorisation.cs @@ -42,9 +42,13 @@ internal static IServiceCollection AddAndConfigureAuthorisation(this IServiceCol options .SetTokenEndpointUris("/connect/token") .SetAuthorizationEndpointUris("/connect/authorize") - .AddEventHandler(builder => builder.UseInlineHandler(OpenIdDictEvents.ValidateAuthorizationRequestFunc(settings.Auth))) + .SetLogoutEndpointUris("/connect/logout") .AddEventHandler(builder => builder.UseInlineHandler(OpenIdDictEvents.ValidateTokenRequestFunc(settings.Auth))) + .AddEventHandler(builder => builder.UseInlineHandler(OpenIdDictEvents.ValidateAuthorizationRequestFunc(settings.Auth))) .AddEventHandler(builder => builder.UseInlineHandler(OpenIdDictEvents.HandleAuthorizationRequest(settings.Auth))) + // Handle Logout + .AddEventHandler(builder => builder.UseInlineHandler(OpenIdDictEvents.ValidateLogoutRequestFunc(settings.Auth))) + .AddEventHandler(builder => builder.UseInlineHandler(OpenIdDictEvents.HandleLogoutRequestFunc(settings.Auth))) // Enable the Authorization Code Flow with PKCE and Refresh Token Flow .AllowAuthorizationCodeFlow() .RequireProofKeyForCodeExchange()