From 09f932f82522be2e5e4b2d30ffabfd2979662440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Rudge?= Date: Fri, 2 Aug 2019 15:57:55 -0300 Subject: [PATCH] Add ?federated logout param (#129) --- __tests__/index.test.ts | 14 ++++++++++++++ src/Auth0Client.ts | 6 ++++-- src/global.ts | 8 ++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index dd416991b..b797f0140 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -947,6 +947,12 @@ describe('Auth0', () => { returnTo: 'https://return.to' }); }); + it('creates correct query params when `options.federated` is true', async () => { + const { auth0, utils } = await setup(); + + auth0.logout({ federated: true, client_id: null }); + expect(utils.createQueryParams).toHaveBeenCalledWith({}); + }); it('calls `window.location.assign` with the correct url', async () => { const { auth0 } = await setup(); @@ -955,6 +961,14 @@ describe('Auth0', () => { `https://test.auth0.com/v2/logout?query=params${TEST_TELEMETRY_QUERY_STRING}` ); }); + it('calls `window.location.assign` with the correct url when `options.federated` is true', async () => { + const { auth0 } = await setup(); + + auth0.logout({ federated: true }); + expect(window.location.assign).toHaveBeenCalledWith( + `https://test.auth0.com/v2/logout?query=params${TEST_TELEMETRY_QUERY_STRING}&federated` + ); + }); }); }); describe('default creation function', () => { diff --git a/src/Auth0Client.ts b/src/Auth0Client.ts index 7a7d74c28..c8178564b 100644 --- a/src/Auth0Client.ts +++ b/src/Auth0Client.ts @@ -403,7 +403,9 @@ export default class Auth0Client { delete options.client_id; } ClientStorage.remove('auth0.is.authenticated'); - const url = this._url(`/v2/logout?${createQueryParams(options)}`); - window.location.assign(url); + const { federated, ...logoutOptions } = options; + const federatedQuery = federated ? `&federated` : ''; + const url = this._url(`/v2/logout?${createQueryParams(logoutOptions)}`); + window.location.assign(`${url}${federatedQuery}`); } } diff --git a/src/global.ts b/src/global.ts index b40cb00a9..e5ba593bb 100644 --- a/src/global.ts +++ b/src/global.ts @@ -176,6 +176,14 @@ interface LogoutOptions { * The `client_id` of your application. */ client_id?: string; + + /** + * When supported by the upstream identity provider, + * forces the user to logout of their identity provider + * and from Auth0. + * [Read more about how federated logout works at Auth0](https://auth0.com/docs/logout/guides/logout-idps) + */ + federated?: boolean; } /**