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

Fix issue setting nextUrl on click of logout button #2040

Draft
wants to merge 3 commits 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
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 @@
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;

Check warning on line 47 in public/apps/account/utils.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/account/utils.tsx#L47

Added line #L47 was not covered by tests
} 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();

Check warning on line 51 in public/apps/account/utils.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/account/utils.tsx#L51

Added line #L51 was not covered by tests
}
}

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(

Check warning on line 59 in public/apps/account/utils.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/account/utils.tsx#L59

Added line #L59 was not covered by tests
window.location.pathname + window.location.search + window.location.hash
);
window.location.href = `${http.basePath.serverBasePath}${logoutEndpoint}?nextUrl=${nextUrl}`;

Check warning on line 62 in public/apps/account/utils.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/account/utils.tsx#L62

Added line #L62 was not covered by tests
}

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
Loading