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

.signOut improvements #1439

Merged
merged 3 commits into from
Jul 27, 2023
Merged

Conversation

jaredperreault-okta
Copy link
Contributor

Resolves #1410 and #1433

  • allows for postLogoutRedirectUri to be null to invoke default /logout redirect behavior
  • returns state as query param to redirect uri when .signOut falls back to .closeSession

@@ -101,7 +101,7 @@ export interface IsAuthenticatedOptions {
}

export interface SignoutRedirectUrlOptions {
postLogoutRedirectUri?: string;
postLogoutRedirectUri?: string | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is null needed here as it's already optional?

@@ -261,7 +261,7 @@ export function mixinOAuth
if (!idToken) {
return '';
}
if (!postLogoutRedirectUri) {
if (postLogoutRedirectUri === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add comment why undefined is handled here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not likely a real issue but I prefer to check typeof foo === 'undefined'

redirectUri.searchParams.append('state', state);
}
if (postLogoutRedirectUri === currentUri) {
// window.location.reload(); // force a hard reload if URI is not changing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this commented code be removed?

Comment on lines +295 to +297
(options.postLogoutRedirectUri
|| this.options.postLogoutRedirectUri
|| defaultUri;
|| defaultUri);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful -- options vs this.options. Is there a difference? Maybe a different variable name would help avoid confusion.

@@ -247,7 +247,7 @@ describe('OktaAuth (browser)', function() {
expect(auth.revokeRefreshToken).toHaveBeenCalledWith(refreshToken);
expect(auth.closeSession).not.toHaveBeenCalled();
expect(window.location.assign).toHaveBeenCalledWith(`${issuer}/oauth2/v1/logout?id_token_hint=${idToken.idToken}&post_logout_redirect_uri=${encodedOrigin}`);
expect(signOutSuccess).toBeTruthy();
expect(signOutSuccess).toBe(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Comment on lines +200 to 201
origin = 'https://somesite.local/';
href = `${origin}/some-route`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk if this matters but href will have a double-/ with the change here

@@ -389,8 +396,8 @@ describe('OktaAuth (browser)', function() {
expect(auth.tokenManager.getTokensSync).toHaveBeenCalledTimes(4);
expect(auth.revokeAccessToken).toHaveBeenCalledWith(accessToken);
expect(auth.closeSession).toHaveBeenCalled();
expect(window.location.reload).toHaveBeenCalled();
expect(signOutSuccess).toBeTruthy();
// expect(window.location.reload).toHaveBeenCalled(); // TODO: confirm href?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The signout function puts a default postLogoutRedirectUri when it's not passed
4 participants