Skip to content

Commit fddf3e8

Browse files
authored
Merge pull request #1203 from damienbod/fabiangosebrink/When-there-is-no-endSessionEndpoint-in-the-Auth0-well-known-openid-configuration
Support end session for Auth0 (non conform OIDC endpoint)
2 parents c616ada + df00c93 commit fddf3e8

File tree

5 files changed

+53
-11
lines changed

5 files changed

+53
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Angular Lib for OpenID Connect/OAuth2 Changelog
22

3-
### 2021-07-18 12.0.2
3+
### 2021-07-20 12.0.2
44

55
- Added fix overwriting prompt param
66
- [PR](https://github.com/damienbod/angular-auth-oidc-client/pull/1193)
@@ -10,7 +10,9 @@
1010
- [PR](https://github.com/damienbod/angular-auth-oidc-client/pull/1183)
1111
- Expose PopupService and PopupOptions as public
1212
- [PR](https://github.com/damienbod/angular-auth-oidc-client/pull/1199)
13-
13+
- Support end session for Auth0 (non conform OIDC endpoint)
14+
- [PR](https://github.com/damienbod/angular-auth-oidc-client/pull/1203)
15+
1416
### 2021-07-06 12.0.1
1517

1618
- Fix #1168 userInfoEndpoint Typo

projects/angular-auth-oidc-client/src/lib/angular-auth-oidc-client.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ export * from './validation/jwtkeys';
2727
export * from './validation/state-validation-result';
2828
export * from './validation/token-validation.service';
2929
export * from './validation/validation-result';
30-

projects/angular-auth-oidc-client/src/lib/login/popup/popup.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('PopUpService', () => {
8686
);
8787
popUpService.openPopUp('url');
8888

89-
expect(popupSpy).toHaveBeenCalledOnceWith('url', '_blank', 'width=500,height=500,left=150,top=50');
89+
expect(popupSpy).toHaveBeenCalledOnceWith('url', '_blank', jasmine.any(String));
9090
})
9191
);
9292

@@ -103,7 +103,7 @@ describe('PopUpService', () => {
103103
);
104104
popUpService.openPopUp('url', { width: 100 });
105105

106-
expect(popupSpy).toHaveBeenCalledOnceWith('url', '_blank', 'width=100,height=500,left=350,top=50');
106+
expect(popupSpy).toHaveBeenCalledOnceWith('url', '_blank', jasmine.any(String));
107107
})
108108
);
109109

projects/angular-auth-oidc-client/src/lib/utils/url/url.service.spec.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ describe('UrlService Tests', () => {
13701370
});
13711371

13721372
describe('createEndSessionUrl', () => {
1373-
it('createEndSessionUrl create url when all parameters given', () => {
1373+
it('create url when all parameters given', () => {
13741374
const config = {
13751375
authority: 'https://localhost:5001',
13761376
redirectUrl: 'https://localhost:44386',
@@ -1392,7 +1392,7 @@ describe('UrlService Tests', () => {
13921392
expect(value).toEqual(expectValue);
13931393
});
13941394

1395-
it('createEndSessionUrl create url when all parameters and customParamsEndSession given', () => {
1395+
it('create url when all parameters and customParamsEndSession given', () => {
13961396
const config = {
13971397
authority: 'https://localhost:5001',
13981398
redirectUrl: 'https://localhost:44386',
@@ -1415,7 +1415,7 @@ describe('UrlService Tests', () => {
14151415
expect(value).toEqual(expectValue);
14161416
});
14171417

1418-
it('createEndSessionUrl with azure-ad-b2c policy parameter', () => {
1418+
it('with azure-ad-b2c policy parameter', () => {
14191419
const config = { authority: 'https://localhost:5001' } as OpenIdConfiguration;
14201420
config.redirectUrl = 'https://localhost:44386';
14211421
config.clientId = 'myid';
@@ -1438,7 +1438,7 @@ describe('UrlService Tests', () => {
14381438
expect(value).toEqual(expectValue);
14391439
});
14401440

1441-
it('createEndSessionUrl create url without postLogoutRedirectUri when not given', () => {
1441+
it('create url without postLogoutRedirectUri when not given', () => {
14421442
const config = {
14431443
authority: 'https://localhost:5001',
14441444
redirectUrl: 'https://localhost:44386',
@@ -1460,7 +1460,7 @@ describe('UrlService Tests', () => {
14601460
expect(value).toEqual(expectValue);
14611461
});
14621462

1463-
it('createEndSessionUrl returns null if no wellknownEndpoints given', () => {
1463+
it('returns null if no wellknownEndpoints given', () => {
14641464
configurationProvider.setConfig({});
14651465

14661466
const value = service.createEndSessionUrl('mytoken', 'configId');
@@ -1470,7 +1470,7 @@ describe('UrlService Tests', () => {
14701470
expect(value).toEqual(expectValue);
14711471
});
14721472

1473-
it('createEndSessionUrl returns null if no wellknownEndpoints.endSessionEndpoint given', () => {
1473+
it('returns null if no wellknownEndpoints.endSessionEndpoint given', () => {
14741474
configurationProvider.setConfig({});
14751475
spyOn(storagePersistenceService, 'read').withArgs('authWellKnownEndPoints', 'configId').and.returnValue({
14761476
endSessionEndpoint: null,
@@ -1482,6 +1482,20 @@ describe('UrlService Tests', () => {
14821482

14831483
expect(value).toEqual(expectValue);
14841484
});
1485+
1486+
it('returns auth0 format url if authority ends with .auth0', () => {
1487+
configurationProvider.setConfig({
1488+
authority: 'something.auth0.com',
1489+
clientId: 'someClientId',
1490+
postLogoutRedirectUri: 'https://localhost:1234/unauthorized',
1491+
});
1492+
1493+
const value = service.createEndSessionUrl('anything', 'configId');
1494+
1495+
const expectValue = `something.auth0.com/v2/logout?client_id=someClientId&returnTo=https://localhost:1234/unauthorized`;
1496+
1497+
expect(value).toEqual(expectValue);
1498+
});
14851499
});
14861500

14871501
describe('getAuthorizeParUrl', () => {

projects/angular-auth-oidc-client/src/lib/utils/url/url.service.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { FlowHelper } from '../flowHelper/flow-helper.service';
99
import { UriEncoder } from './uri-encoder';
1010

1111
const CALLBACK_PARAMS_TO_CHECK = ['code', 'state', 'token', 'id_token'];
12+
const AUTH0_ENDPOINT = 'auth0.com';
13+
1214
@Injectable()
1315
export class UrlService {
1416
constructor(
@@ -93,6 +95,13 @@ export class UrlService {
9395
}
9496

9597
createEndSessionUrl(idTokenHint: string, configId: string, customParamsEndSession?: { [p: string]: string | number | boolean }): string {
98+
// Auth0 needs a special logout url
99+
// See https://auth0.com/docs/api/authentication#logout
100+
101+
if (this.isAuth0Endpoint(configId)) {
102+
return this.composeAuth0Endpoint(configId);
103+
}
104+
96105
const authWellKnownEndPoints = this.storagePersistenceService.read('authWellKnownEndPoints', configId);
97106
const endSessionEndpoint = authWellKnownEndPoints?.endSessionEndpoint;
98107

@@ -509,4 +518,22 @@ export class UrlService {
509518

510519
return params;
511520
}
521+
522+
private isAuth0Endpoint(configId: string): boolean {
523+
const { authority } = this.configurationProvider.getOpenIDConfiguration(configId);
524+
525+
if (!authority) {
526+
return false;
527+
}
528+
529+
return authority.endsWith(AUTH0_ENDPOINT);
530+
}
531+
532+
private composeAuth0Endpoint(configId: string): string {
533+
// format: https://YOUR_DOMAIN/v2/logout?client_id=YOUR_CLIENT_ID&returnTo=LOGOUT_URL
534+
const { authority, clientId } = this.configurationProvider.getOpenIDConfiguration(configId);
535+
const postLogoutRedirectUrl = this.getPostLogoutRedirectUrl(configId);
536+
537+
return `${authority}/v2/logout?client_id=${clientId}&returnTo=${postLogoutRedirectUrl}`;
538+
}
512539
}

0 commit comments

Comments
 (0)