diff --git a/CHANGELOG.md b/CHANGELOG.md index c99090bff..ab3b4a2e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ - [#1050](https://github.com/okta/okta-auth-js/pull/1050) Removes `userAgent` field from oktaAuth instance - [#1014](https://github.com/okta/okta-auth-js/pull/1014) Shared transaction storage is automatically cleared on success and error states. Storage is not cleared for "terminal" state which is neither success nor error. - [#1051](https://github.com/okta/okta-auth-js/pull/1051) Removes `useMultipleCookies` from CookieStorage options +- [#1059](https://github.com/okta/okta-auth-js/pull/1059) + - Removes signOut option `clearTokensAfterRedirect` + - Adds signOut option `clearTokensBeforeRedirect` (default: `false`) to remove local tokens before logout redirect happen ### Features diff --git a/README.md b/README.md index 871e8dad8..f4232b5ba 100644 --- a/README.md +++ b/README.md @@ -928,7 +928,7 @@ Signs the user out of their current [Okta session](https://developer.okta.com/do * `postLogoutRedirectUri` - Setting a value will override the `postLogoutRedirectUri` configured on the SDK. * `state` - An optional value, used along with `postLogoutRedirectUri`. If set, this value will be returned as a query parameter during the redirect to the `postLogoutRedirectUri` * `idToken` - Specifies the ID token object. By default, `signOut` will look for a token object named `idToken` within the `TokenManager`. If you have stored the id token object in a different location, you should retrieve it first and then pass it here. -* `clearTokensAfterRedirect` - If `true` (default: `false`) a flag (`pendingRemove`) will be added to local tokens instead of clearing them immediately. Calling `oktaAuth.start()` after logout redirect will clear local tokens if flags are found. This option can be used when work with `SecureRoute` component from Okta's downstream client SDKs to guarantee the local tokens can only be cleared after the Okta SSO session is fully killed. +* `clearTokensBeforeRedirect` - If `true` (default: `false`) local tokens will be removed before the logout redirect happen. Otherwise a flag (`pendingRemove`) will be added to each local token instead of clearing them immediately. Calling `oktaAuth.start()` after logout redirect will clear local tokens if flags are found. Use this option with care: removing local tokens before fully kill the Okta SSO session can result in logging back in again when `SecureRoute` component from Okta's downstream client SDKs is used in the application. * `revokeAccessToken` - If `false` (default: `true`) the access token will not be revoked. Use this option with care: not revoking tokens may pose a security risk if tokens have been leaked outside the application. * `revokeRefreshToken` - If `false` (default: `true`) the refresh token will not be revoked. Use this option with care: not revoking tokens may pose a security risk if tokens have been leaked outside the application. Revoking a refresh token will revoke any access tokens minted by it, even if `revokeAccessToken` is `false`. * `accessToken` - Specifies the access token object. By default, `signOut` will look for a token object named `accessToken` within the `TokenManager`. If you have stored the access token object in a different location, you should retrieve it first and then pass it here. This options is ignored if the `revokeAccessToken` option is `false`. diff --git a/lib/OktaAuth.ts b/lib/OktaAuth.ts index d301f4013..8d86314d7 100644 --- a/lib/OktaAuth.ts +++ b/lib/OktaAuth.ts @@ -510,11 +510,11 @@ class OktaAuth implements SDKInterface, SigninAPI, SignoutAPI { } }); } else { - if (options.clearTokensAfterRedirect) { - this.tokenManager.addPendingRemoveFlags(); - } else { + if (options.clearTokensBeforeRedirect) { // Clear all local tokens this.tokenManager.clear(); + } else { + this.tokenManager.addPendingRemoveFlags(); } // Flow ends with logout redirect window.location.assign(logoutUri); diff --git a/lib/types/api.ts b/lib/types/api.ts index e5b4900a0..f7560f615 100644 --- a/lib/types/api.ts +++ b/lib/types/api.ts @@ -243,7 +243,7 @@ export interface SignoutOptions extends SignoutRedirectUrlOptions { revokeRefreshToken?: boolean; accessToken?: AccessToken; refreshToken?: RefreshToken; - clearTokensAfterRedirect?: boolean; + clearTokensBeforeRedirect?: boolean; } export interface SignoutAPI { diff --git a/test/apps/app/public/static/index.html b/test/apps/app/public/static/index.html index 045874c91..68f6204dc 100644 --- a/test/apps/app/public/static/index.html +++ b/test/apps/app/public/static/index.html @@ -109,7 +109,9 @@ function logout(e) { e.preventDefault(); - authClient.signOut() + // authClient.start() is not triggered by default + // clear local tokens before redirect to end up with correct authState + authClient.signOut({ clearTokensBeforeRedirect: true }) } main(); diff --git a/test/apps/app/src/testApp.ts b/test/apps/app/src/testApp.ts index 55a21a8e6..709005bd3 100644 --- a/test/apps/app/src/testApp.ts +++ b/test/apps/app/src/testApp.ts @@ -97,10 +97,10 @@ function logoutLink(app: TestApp): string {