Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logout handling #12

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions OpenIdDict.Server/Authorisation/OpenIdDictEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
};

/// <summary>
/// Validation of `/logout` requests
/// </summary>
internal static Func<OpenIddictServerEvents.ValidateLogoutRequestContext, ValueTask> ValidateLogoutRequestFunc(AppSettings.AuthCredentialsSettings authSettings) =>
context =>
{
ArgumentNullException.ThrowIfNull(context);

if (string.IsNullOrEmpty(context.PostLogoutRedirectUri))
return default;

// Optionally, can validate the `PostLogoutRedirectUri`
return default;
};

/// <summary>
/// Handling of `/logout` requests
/// </summary>
internal static Func<OpenIddictServerEvents.HandleLogoutRequestContext, ValueTask> HandleLogoutRequestFunc(AppSettings.AuthCredentialsSettings authSettings) =>
context =>
{
context.SignOut();
return default;
};

/// <summary>
/// Resolving mandatory email from a relevant mapped claim
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ internal static IServiceCollection AddAndConfigureAuthorisation(this IServiceCol
options
.SetTokenEndpointUris("/connect/token")
.SetAuthorizationEndpointUris("/connect/authorize")
.AddEventHandler<OpenIddictServerEvents.ValidateAuthorizationRequestContext>(builder => builder.UseInlineHandler(OpenIdDictEvents.ValidateAuthorizationRequestFunc(settings.Auth)))
.SetLogoutEndpointUris("/connect/logout")
.AddEventHandler<OpenIddictServerEvents.ValidateTokenRequestContext>(builder => builder.UseInlineHandler(OpenIdDictEvents.ValidateTokenRequestFunc(settings.Auth)))
.AddEventHandler<OpenIddictServerEvents.ValidateAuthorizationRequestContext>(builder => builder.UseInlineHandler(OpenIdDictEvents.ValidateAuthorizationRequestFunc(settings.Auth)))
.AddEventHandler<OpenIddictServerEvents.HandleAuthorizationRequestContext>(builder => builder.UseInlineHandler(OpenIdDictEvents.HandleAuthorizationRequest(settings.Auth)))
// Handle Logout
.AddEventHandler<OpenIddictServerEvents.ValidateLogoutRequestContext>(builder => builder.UseInlineHandler(OpenIdDictEvents.ValidateLogoutRequestFunc(settings.Auth)))
.AddEventHandler<OpenIddictServerEvents.HandleLogoutRequestContext>(builder => builder.UseInlineHandler(OpenIdDictEvents.HandleLogoutRequestFunc(settings.Auth)))
// Enable the Authorization Code Flow with PKCE and Refresh Token Flow
.AllowAuthorizationCodeFlow()
.RequireProofKeyForCodeExchange()
Expand Down
Loading