Skip to content
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
17 changes: 11 additions & 6 deletions public/apps/account/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,23 @@ export async function logout(http: HttpStart, logoutUrl?: string): Promise<void>
setShouldShowTenantPopup(null);
// Clear everything in the sessionStorage since they can contain sensitive information
sessionStorage.clear();
// When no basepath is set, we can take '/' as the basepath.
const basePath = http.basePath.serverBasePath ? http.basePath.serverBasePath : '/';
const nextUrl = encodeURIComponent(basePath);
window.location.href =
logoutUrl || `${http.basePath.serverBasePath}/app/login?nextUrl=${nextUrl}`;
if (logoutUrl) {
window.location.href = logoutUrl;
} else {
// when session timed out, user credentials in cookie are wiped out
// refresh the page will direct the user to go through login process
window.location.reload();
}
}

export async function externalLogout(http: HttpStart, logoutEndpoint: string): Promise<void> {
// This will ensure tenancy is picked up from local storage in the next login.
setShouldShowTenantPopup(null);
sessionStorage.clear();
window.location.href = `${http.basePath.serverBasePath}${logoutEndpoint}`;
const nextUrl = encodeURIComponent(
window.location.pathname + window.location.search + window.location.hash
);
window.location.href = `${http.basePath.serverBasePath}${logoutEndpoint}?nextUrl=${nextUrl}`;
}

export async function updateNewPassword(
Expand Down
2 changes: 1 addition & 1 deletion public/utils/logout-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function interceptError(logoutUrl: string, thisWindow: Window): any {
thisWindow.location.href = logoutUrl;
} else {
// when session timed out, user credentials in cookie are wiped out
// refres the page will direct the user to go through login process
// refresh the page will direct the user to go through login process
thisWindow.location.reload();
}
}
Expand Down
7 changes: 6 additions & 1 deletion server/auth/types/openid/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,12 @@ export class OpenIdAuthRoutes {
const token = tokenFromExtraStorage.length
? tokenFromExtraStorage.split(' ')[1]
: cookie?.credentials.authHeaderValue.split(' ')[1]; // get auth token
const nextUrl = getBaseRedirectUrl(this.config, this.core, request);
let nextUrl = getBaseRedirectUrl(this.config, this.core, request);
if (request.url.searchParams.has('nextUrl') && !!request.url.searchParams.get('nextUrl')) {
nextUrl = `${nextUrl}/app/login?nextUrl=${encodeURIComponent(
request.url.searchParams.get('nextUrl') || ''
)}`;
}

const logoutQueryParams = {
post_logout_redirect_uri: `${nextUrl}`,
Expand Down
10 changes: 8 additions & 2 deletions server/auth/types/saml/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,15 @@ export class SamlAuthRoutes {
this.getExtraAuthStorageOptions(context.security_plugin.logger)
);
this.sessionStorageFactory.asScoped(request).clear();

let loginUrl = `${this.coreSetup.http.basePath.serverBasePath}/app/login`;
if (request.url.searchParams.has('nextUrl')) {
loginUrl = `${loginUrl}?nextUrl=${encodeURIComponent(
request.url.searchParams.get('nextUrl') || ''
)}`;
}
// TODO: need a default logout page
const redirectUrl =
authInfo.sso_logout_url || this.coreSetup.http.basePath.serverBasePath || '/';
const redirectUrl = authInfo.sso_logout_url || loginUrl;
return response.redirected({
headers: {
location: redirectUrl,
Expand Down