Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit f2e43b3

Browse files
eromanonelsonsilva
andauthored
Support custom OAuth endpoints (#1259)
Co-authored-by: Nelson Silva <nsilva@nuxeo.com>
1 parent 05e881f commit f2e43b3

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ refreshTokenTimeout| millisecond value, after how many millisecond you want ref
254254
redirectSilentIframeUri| url to be redirect after silent refresh login| /assets/silent-refresh.html |
255255
silentLogin| direct execute the implicit login without the need to call AlfrescoJsApi.implicitLogin() method| false|
256256
publicUrls | list of public urls that don't need authorization. It is possible too pass absolute paths and string patterns that are valid for [minimatch](https://github.com/isaacs/minimatch#readme) |
257+
authorizationUrl| authorization url, relative to the host| /protocol/openid-connect/auth|
258+
tokenUrl| token url, relative to the host| /protocol/openid-connect/token|
259+
logoutUrl| logout url, relative to the host| /protocol/openid-connect/logout|
257260

258261
The api/js-api will automatically redirect you to the login page anf refresh the token if necessary
259262

src/authentication/oauth2Auth.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,22 @@ declare let window: Window;
3232

3333
export class Oauth2Auth extends AlfrescoApiClient {
3434

35+
static readonly DEFAULT_AUTHORIZATION_URL = '/protocol/openid-connect/auth';
36+
static readonly DEFAULT_TOKEN_URL = '/protocol/openid-connect/token';
37+
static readonly DEFAULT_LOGOUT_URL = '/protocol/openid-connect/logout';
38+
3539
private refreshTokenIntervalPolling: any;
3640
private refreshTokenTimeoutIframe: any;
3741
private checkAccessToken = true;
3842
storage: Storage;
3943

4044
hashFragmentParams: any;
4145
token: string;
42-
discovery: any = {};
46+
discovery: {
47+
loginUrl?: string;
48+
logoutUrl?: string;
49+
tokenEndpoint?: string;
50+
} = {};
4351

4452
authentications: Authentication = {
4553
'oauth2': { accessToken: '' }, type: 'oauth2', 'basicAuth': {}
@@ -121,9 +129,9 @@ export class Oauth2Auth extends AlfrescoApiClient {
121129
}
122130

123131
discoveryUrls() {
124-
this.discovery.loginUrl = `${this.host}/protocol/openid-connect/auth`;
125-
this.discovery.logoutUrl = `${this.host}/protocol/openid-connect/logout`;
126-
this.discovery.tokenEndpoint = `${this.host}/protocol/openid-connect/token`;
132+
this.discovery.loginUrl = this.host + (this.config.oauth2.authorizationUrl || Oauth2Auth.DEFAULT_AUTHORIZATION_URL);
133+
this.discovery.logoutUrl = this.host + (this.config.oauth2.logoutUrl || Oauth2Auth.DEFAULT_LOGOUT_URL);
134+
this.discovery.tokenEndpoint = this.host + (this.config.oauth2.tokenUrl || Oauth2Auth.DEFAULT_TOKEN_URL);
127135
}
128136

129137
hasContentProvider(): boolean {

src/authentication/oauth2Config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export interface Oauth2Config {
1919
clientId: string;
2020
secret?: string;
2121
host: string;
22+
authorizationUrl?: string;
23+
tokenUrl?: string;
24+
logoutUrl?: string;
2225
scope: string;
2326
implicitFlow?: boolean;
2427
redirectUri: string;

test/oauth2Auth.spec.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,59 @@ describe('Oauth2 test', () => {
3030
});
3131
});
3232

33+
describe('Discovery urls', () => {
34+
const authType = 'OAUTH';
35+
const host = 'http://dummy/auth';
36+
const clientId = 'dummy';
37+
const scope = 'openid';
38+
const redirectUri = '/';
39+
40+
it('should have default urls', async () => {
41+
const oauth2Auth = new Oauth2Auth(
42+
<AlfrescoApiConfig> {
43+
oauth2: {
44+
host,
45+
clientId,
46+
scope,
47+
redirectUri
48+
},
49+
authType
50+
},
51+
alfrescoJsApi
52+
);
53+
54+
expect(oauth2Auth.discovery.loginUrl).to.be.equal(host + Oauth2Auth.DEFAULT_AUTHORIZATION_URL);
55+
expect(oauth2Auth.discovery.tokenEndpoint).to.be.equal(host + Oauth2Auth.DEFAULT_TOKEN_URL);
56+
expect(oauth2Auth.discovery.logoutUrl).to.be.equal(host + Oauth2Auth.DEFAULT_LOGOUT_URL);
57+
});
58+
59+
it('should be possible to override the default urls', async () => {
60+
const authorizationUrl = '/custom-login';
61+
const logoutUrl = '/custom-logout';
62+
const tokenUrl = '/custom-token';
63+
const oauth2Auth = new Oauth2Auth(
64+
<AlfrescoApiConfig> {
65+
oauth2: {
66+
host,
67+
authorizationUrl,
68+
logoutUrl,
69+
tokenUrl,
70+
clientId,
71+
scope,
72+
redirectUri
73+
},
74+
authType
75+
},
76+
alfrescoJsApi
77+
);
78+
79+
expect(oauth2Auth.discovery.loginUrl).to.be.equal(host + authorizationUrl);
80+
expect(oauth2Auth.discovery.tokenEndpoint).to.be.equal(host + tokenUrl);
81+
expect(oauth2Auth.discovery.logoutUrl).to.be.equal(host + logoutUrl);
82+
});
83+
84+
});
85+
3386
describe('With Authentication', () => {
3487

3588
it('should be possible have different user login in different instance of the oauth2Auth class', async () => {

0 commit comments

Comments
 (0)