Skip to content

Commit 61c0c2c

Browse files
1771 - Set id_token_hint when logging out (Signed) (#2151)
Co-authored-by: simon-debruijn <simon.debruijn@hotmail.com>
1 parent c633b12 commit 61c0c2c

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

src/auth0-session/client/edge-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export class EdgeClient extends AbstractClient {
218218
this.config.idpLogout &&
219219
(this.config.auth0Logout || (issuerUrl.hostname.match('\\.auth0\\.com$') && this.config.auth0Logout !== false))
220220
) {
221-
const { id_token_hint, post_logout_redirect_uri, ...extraParams } = parameters;
221+
const { post_logout_redirect_uri, ...extraParams } = parameters;
222222
const auth0LogoutUrl: URL = new URL(urlJoin(as.issuer, '/v2/logout'));
223223
post_logout_redirect_uri && auth0LogoutUrl.searchParams.set('returnTo', post_logout_redirect_uri);
224224
auth0LogoutUrl.searchParams.set('client_id', this.config.clientID);

src/auth0-session/client/node-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class NodeClient extends AbstractClient {
147147
) {
148148
Object.defineProperty(this.client, 'endSessionUrl', {
149149
value(params: EndSessionParameters) {
150-
const { id_token_hint, post_logout_redirect_uri, ...extraParams } = params;
150+
const { post_logout_redirect_uri, ...extraParams } = params;
151151
const parsedUrl = new URL(urlJoin(issuer.metadata.issuer, '/v2/logout'));
152152
parsedUrl.searchParams.set('client_id', config.clientID);
153153
post_logout_redirect_uri && parsedUrl.searchParams.set('returnTo', post_logout_redirect_uri);

tests/auth0-session/client/edge-client.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,24 @@ describe('edge client', function () {
235235
);
236236
});
237237

238+
it('should create custom logout for auth0 with id_token_hint', async function () {
239+
nock('https://test.eu.auth0.com')
240+
.get('/.well-known/openid-configuration')
241+
.reply(200, { ...wellKnown, issuer: 'https://test.eu.auth0.com/', end_session_endpoint: undefined });
242+
nock('https://test.eu.auth0.com').get('/.well-known/jwks.json').reply(200, jwks);
243+
244+
const client = await getClient({
245+
issuerBaseURL: 'https://test.eu.auth0.com',
246+
idpLogout: true,
247+
});
248+
249+
const idToken = await makeIdToken()
250+
251+
await expect(client.endSessionUrl({ post_logout_redirect_uri: 'foo', id_token_hint: idToken })).resolves.toEqual(
252+
`https://test.eu.auth0.com/v2/logout?returnTo=foo&client_id=__test_client_id__&id_token_hint=${idToken}`
253+
);
254+
});
255+
238256
it('should remove null params from oidc logout endpoint', async function () {
239257
const client = await getClient({ ...defaultConfig, idpLogout: true });
240258
await expect(client.endSessionUrl({ foo: null } as any)).resolves.toEqual(

tests/auth0-session/client/node-client.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import nock from 'nock';
22
import { getConfig, ConfigParameters } from '../../../src/auth0-session';
3-
import { jwks } from '../fixtures/cert';
3+
import { jwks, makeIdToken } from '../fixtures/cert';
44
import pkg from '../../../package.json';
55
import wellKnown from '../fixtures/well-known.json';
66
import version from '../../../src/version';
@@ -180,6 +180,24 @@ describe('node client', function () {
180180
);
181181
});
182182

183+
it('should create custom logout for auth0 with id_token_hint', async function () {
184+
nock('https://test.eu.auth0.com')
185+
.get('/.well-known/openid-configuration')
186+
.reply(200, { ...wellKnown, issuer: 'https://test.eu.auth0.com/', end_session_endpoint: undefined });
187+
nock('https://test.eu.auth0.com').get('/.well-known/jwks.json').reply(200, jwks);
188+
189+
const client = await getClient({
190+
issuerBaseURL: 'https://test.eu.auth0.com',
191+
idpLogout: true,
192+
});
193+
194+
const idToken = await makeIdToken()
195+
196+
await expect(client.endSessionUrl({ post_logout_redirect_uri: 'foo', id_token_hint: idToken })).resolves.toEqual(
197+
`https://test.eu.auth0.com/v2/logout?client_id=__test_client_id__&returnTo=foo&id_token_hint=${idToken}`
198+
);
199+
});
200+
183201
it('should handle limited openid-configuration', async function () {
184202
nock('https://op2.example.com')
185203
.get('/.well-known/openid-configuration')

0 commit comments

Comments
 (0)