Skip to content

Commit

Permalink
Add ?federated logout param (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
luisrudge authored Aug 2, 2019
1 parent 202d261 commit 09f932f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
14 changes: 14 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
8 changes: 8 additions & 0 deletions src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 09f932f

Please sign in to comment.