Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
[AAE-8649] Being able to use input values of discovery (#1378)
Browse files Browse the repository at this point in the history
* Use the discovery input if passed

* Move the setting into proper method

* Fix unit test with relative link
  • Loading branch information
mauriziovitale authored May 9, 2022
1 parent befd13c commit 470d9c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/authentication/oauth2Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ export class Oauth2Auth extends AlfrescoApiClient {
loginUrl?: string;
logoutUrl?: string;
tokenEndpoint?: string;
} = {};
} = {
loginUrl: undefined,
logoutUrl: undefined,
tokenEndpoint: undefined,
};

authentications: Authentication = {
'oauth2': { accessToken: '' }, type: 'oauth2', 'basicAuth': {}
Expand All @@ -58,7 +62,6 @@ export class Oauth2Auth extends AlfrescoApiClient {
constructor(config: AlfrescoApiConfig, alfrescoApi: AlfrescoApi) {
super();
this.storage = new Storage();
this.storage.setDomainPrefix(config.domainPrefix);

this.className = 'Oauth2Auth';

Expand All @@ -69,6 +72,7 @@ export class Oauth2Auth extends AlfrescoApiClient {

setConfig(config: AlfrescoApiConfig, alfrescoApi: AlfrescoApi) {
this.config = config;
this.storage.setDomainPrefix(config.domainPrefix);

if (this.config.oauth2) {
if (this.config.oauth2.host === undefined || this.config.oauth2.host === null) {
Expand Down Expand Up @@ -128,10 +132,10 @@ export class Oauth2Auth extends AlfrescoApiClient {
}
}

discoveryUrls() {
this.discovery.loginUrl = this.host + (this.config.oauth2.authorizationUrl || Oauth2Auth.DEFAULT_AUTHORIZATION_URL);
this.discovery.logoutUrl = this.host + (this.config.oauth2.logoutUrl || Oauth2Auth.DEFAULT_LOGOUT_URL);
this.discovery.tokenEndpoint = this.host + (this.config.oauth2.tokenUrl || Oauth2Auth.DEFAULT_TOKEN_URL);
discoveryUrls() {
this.discovery.loginUrl = this.config.oauth2.authorizationUrl || this.host + Oauth2Auth.DEFAULT_AUTHORIZATION_URL;
this.discovery.logoutUrl = this.config.oauth2.logoutUrl || this.host + Oauth2Auth.DEFAULT_LOGOUT_URL;
this.discovery.tokenEndpoint = this.config.oauth2.tokenUrl || this.host + Oauth2Auth.DEFAULT_TOKEN_URL;
}

hasContentProvider(): boolean {
Expand Down
7 changes: 4 additions & 3 deletions test/oauth2Auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('Oauth2 test', () => {
oauth2Mock = new OAuthMock(hostOauth2);
authResponseMock = new EcmAuthMock(hostOauth2);


alfrescoJsApi = new AlfrescoApi({
hostEcm: 'myecm'
} as AlfrescoApiConfig);
Expand Down Expand Up @@ -76,9 +77,9 @@ describe('Oauth2 test', () => {
alfrescoJsApi
);

expect(oauth2Auth.discovery.loginUrl).to.be.equal(host + authorizationUrl);
expect(oauth2Auth.discovery.tokenEndpoint).to.be.equal(host + tokenUrl);
expect(oauth2Auth.discovery.logoutUrl).to.be.equal(host + logoutUrl);
expect(oauth2Auth.discovery.loginUrl).to.be.equal(authorizationUrl);
expect(oauth2Auth.discovery.tokenEndpoint).to.be.equal(tokenUrl);
expect(oauth2Auth.discovery.logoutUrl).to.be.equal(logoutUrl);
});

});
Expand Down

0 comments on commit 470d9c3

Please sign in to comment.