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

Expose SaveTokens option #16

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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Unreleased

Expose `SaveTokens` option on `OneLoginOptions`.


## 0.3.1

Adds `NationalInsuranceNumber` member to `OneLoginClaimTypes`.
Expand Down
15 changes: 11 additions & 4 deletions src/GovUk.OneLogin.AspNetCore/OneLoginOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public OneLoginOptions()
GetClaimsFromUserInfoEndpoint = true,
UseTokenLifetime = false,

// We'll save the ID token ourselves - we need it for sign out
SaveTokens = false,

MapInboundClaims = false,
DisableTelemetry = true
};
Expand Down Expand Up @@ -156,6 +153,13 @@ public CookieBuilder CorrelationCookie
/// <inheritdoc cref="OpenIdConnectOptions.Events"/>
public OpenIdConnectEvents Events { get; }

/// <inheritdoc cref="RemoteAuthenticationOptions.SaveTokens"/>
public bool SaveTokens
{
get => OpenIdConnectOptions.SaveTokens;
set => OpenIdConnectOptions.SaveTokens = value;
}

internal OpenIdConnectOptions OpenIdConnectOptions { get; private set; }

internal bool IncludesCoreIdentityClaim => Claims.Contains(OneLoginClaimTypes.CoreIdentity);
Expand Down Expand Up @@ -223,7 +227,10 @@ internal Task OnRedirectToIdentityProvider(RedirectContext context)

internal Task OnTokenResponseReceived(TokenResponseReceivedContext context)
{
if (context.TokenEndpointResponse.IdToken is string idToken)
// Always store the id_token, even if SaveTokens is false;
// without it sign out doesn't work end-to-end.

if (!context.Options.SaveTokens && context.TokenEndpointResponse.IdToken is string idToken)
{
context.Properties?.StoreTokens(new[]
{
Expand Down
Loading