add /logout to post logout uri redirect in the signout method

This commit is contained in:
Jacob Overgaard
2024-04-09 14:25:37 +02:00
parent d99104e800
commit 27271b1fe6
4 changed files with 24 additions and 5 deletions

View File

@@ -65,7 +65,9 @@ export class UmbAppAuthController extends UmbControllerBase {
}
// Save location.href so we can redirect to it after login
window.sessionStorage.setItem(UMB_STORAGE_REDIRECT_URL, location.href);
if (location.href !== this.#authContext.getPostLogoutRedirectUrl()) {
window.sessionStorage.setItem(UMB_STORAGE_REDIRECT_URL, location.href);
}
// If the user is timed out, we can show the login modal directly
if (userLoginState === 'timedOut') {
@@ -90,7 +92,10 @@ export class UmbAppAuthController extends UmbControllerBase {
this.#authContext.makeAuthorizationRequest();
} else {
// Check if any provider is redirecting directly to the provider
const redirectProvider = availableProviders.find((provider) => provider.meta?.behavior?.autoRedirect);
const redirectProvider =
userLoginState === 'loggingIn'
? availableProviders.find((provider) => provider.meta?.behavior?.autoRedirect)
: undefined;
if (redirectProvider) {
// Redirect directly to the provider

View File

@@ -56,6 +56,13 @@ export class UmbAppElement extends UmbLitElement {
component: () => import('../upgrader/upgrader.element.js'),
guards: [this.#isAuthorizedGuard()],
},
{
path: 'logout',
resolve: () => {
this.#authContext?.clearTokenStorage();
this.#authController.makeAuthorizationRequest('loggedOut');
},
},
{
path: '**',
component: () => import('../backoffice/backoffice.element.js'),

View File

@@ -89,6 +89,7 @@ export class UmbAuthFlow {
// state
readonly #configuration: AuthorizationServiceConfiguration;
readonly #redirectUri: string;
readonly #postLogoutRedirectUri: string;
readonly #clientId: string;
readonly #scope: string;
@@ -99,10 +100,12 @@ export class UmbAuthFlow {
constructor(
openIdConnectUrl: string,
redirectUri: string,
postLogoutRedirectUri: string,
clientId = 'umbraco-back-office',
scope = 'offline_access',
) {
this.#redirectUri = redirectUri;
this.#postLogoutRedirectUri = postLogoutRedirectUri;
this.#clientId = clientId;
this.#scope = scope;
@@ -283,7 +286,7 @@ export class UmbAuthFlow {
// which will redirect the user back to the client
// and the client will then try and log in again (if the user is not logged in)
// which will redirect the user to the login page
location.href = `${this.#configuration.endSessionEndpoint}?post_logout_redirect_uri=${this.#redirectUri}`;
location.href = `${this.#configuration.endSessionEndpoint}?post_logout_redirect_uri=${this.#postLogoutRedirectUri}`;
}
/**

View File

@@ -26,7 +26,7 @@ export class UmbAuthContext extends UmbContextBase<UmbAuthContext> {
this.#serverUrl = serverUrl;
this.#backofficePath = backofficePath;
this.#authFlow = new UmbAuthFlow(serverUrl, this.#getRedirectUrl());
this.#authFlow = new UmbAuthFlow(serverUrl, this.getRedirectUrl(), this.getPostLogoutRedirectUrl());
}
/**
@@ -166,7 +166,11 @@ export class UmbAuthContext extends UmbContextBase<UmbAuthContext> {
return this.isInitialized.pipe(switchMap(() => umbExtensionsRegistry.byType('authProvider')));
}
#getRedirectUrl() {
getRedirectUrl() {
return `${window.location.origin}${this.#backofficePath}`;
}
getPostLogoutRedirectUrl() {
return `${window.location.origin}${this.#backofficePath.endsWith('/') ? this.#backofficePath : this.#backofficePath + '/'}logout`;
}
}