Skip to content

Commit 364f909

Browse files
authored
Merge pull request #195 from yathindrakodithuwakku/revert-contract-revamp
Revert contract revamp
2 parents 6335dec + d68bb87 commit 364f909

File tree

5 files changed

+63
-20
lines changed

5 files changed

+63
-20
lines changed

lib/src/constants/oidc-endpoints.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ export const SERVICE_RESOURCES: OIDCEndpoints = {
2626
jwksUri: "/oauth2/jwks",
2727
revocationEndpoint: "/oauth2/revoke",
2828
tokenEndpoint: "/oauth2/token",
29-
userinfoEndpoint: "/oauth2/userinfo"
29+
userinfoEndpoint: "/oauth2/userinfo",
30+
/**
31+
* The well known endpoint path.
32+
* @deprecated This will be removed in the next version bump 2.0.0
33+
* as this is already defined in config.wellKnownEndpoint.
34+
*/
35+
wellKnownEndpoint: "/oauth2/token/.well-known/openid-configuration"
3036
};
3137

3238
export const AUTHORIZATION_ENDPOINT = "authorization_endpoint";

lib/src/core/authentication-core.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,10 @@ export class AuthenticationCore<T> {
438438
return Promise.resolve();
439439
}
440440

441-
if ((configData as any).wellKnownEndpoint) {
442-
const wellKnownEndpoint = (configData as any).wellKnownEndpoint;
441+
const wellKnownEndpoint = (configData as any).wellKnownEndpoint ||
442+
configData?.endpoints?.wellKnownEndpoint;
443+
444+
if (wellKnownEndpoint) {
443445

444446
let response: Response;
445447

@@ -506,7 +508,8 @@ export class AuthenticationCore<T> {
506508
registrationEndpoint: oidcProviderMetaData.registration_endpoint ?? "",
507509
revocationEndpoint: oidcProviderMetaData.revocation_endpoint ?? "",
508510
tokenEndpoint: oidcProviderMetaData.token_endpoint ?? "",
509-
userinfoEndpoint: oidcProviderMetaData.userinfo_endpoint ?? ""
511+
userinfoEndpoint: oidcProviderMetaData.userinfo_endpoint ?? "",
512+
wellKnownEndpoint: await this._authenticationHelper.resolveWellKnownEndpoint()
510513
};
511514
}
512515

@@ -585,6 +588,12 @@ export class AuthenticationCore<T> {
585588

586589
public async updateConfig(config: Partial<AuthClientConfig<T>>): Promise<void> {
587590
await this._dataLayer.setConfigData(config);
588-
await this.getOIDCProviderMetaData(true);
591+
592+
if ((config as any).overrideWellEndpointConfig) {
593+
config?.endpoints &&
594+
(await this._dataLayer.setOIDCProviderMetaData(await this._authenticationHelper.resolveEndpoints({})));
595+
} else if (config?.endpoints) {
596+
await this.getOIDCProviderMetaData(true);
597+
}
589598
}
590599
}

lib/src/helpers/authentication-helper.ts

+24-7
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,34 @@ export class AuthenticationHelper<T> {
6464
this._cryptoHelper = cryptoHelper;
6565
}
6666

67+
public async resolveWellKnownEndpoint(): Promise<string> {
68+
const configData = await this._config();
69+
70+
const wellKnownEndpoint = (configData as any).wellKnownEndpoint ||
71+
configData?.endpoints?.wellKnownEndpoint;
72+
73+
const baseUrl = (configData as any).baseUrl || (configData as any).serverOrigin;
74+
75+
if (wellKnownEndpoint) {
76+
return wellKnownEndpoint;
77+
} else {
78+
return baseUrl + SERVICE_RESOURCES.wellKnownEndpoint;
79+
}
80+
}
81+
6782
public async resolveEndpoints(response: OIDCProviderMetaData): Promise<OIDCProviderMetaData> {
6883
const oidcProviderMetaData = {};
6984
const configData = await this._config();
7085

71-
configData.endpoints &&
72-
Object.keys(configData.endpoints).forEach((endpointName: string) => {
73-
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${ letter.toLowerCase() }`);
74-
oidcProviderMetaData[ snakeCasedName ] = configData?.endpoints
75-
? configData.endpoints[ endpointName ]
76-
: "";
77-
});
86+
if (configData.overrideWellEndpointConfig) {
87+
configData.endpoints &&
88+
Object.keys(configData.endpoints).forEach((endpointName: string) => {
89+
const snakeCasedName = endpointName.replace(/[A-Z]/g, (letter) => `_${ letter.toLowerCase() }`);
90+
oidcProviderMetaData[ snakeCasedName ] = configData?.endpoints
91+
? configData.endpoints[ endpointName ]
92+
: "";
93+
});
94+
}
7895

7996
return { ...response, ...oidcProviderMetaData };
8097
}

lib/src/models/client-config.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,19 @@ export interface DefaultAuthClientConfig {
3131
scope?: string[];
3232
validateIDToken?: boolean;
3333
/**
34-
* Allowed leeway for id_tokens (in seconds).
34+
* The allow explicitly override oidc endpoints.
35+
* @deprecated This will be removed in the next version bump 2.0.0.
3536
*/
37+
overrideWellEndpointConfig?: boolean;
38+
/**
39+
* Allowed leeway for id_tokens (in seconds).
40+
*/
3641
clockTolerance?: number;
3742
/**
38-
* Specifies if cookies should be sent with access-token requests, refresh-token requests,
39-
* custom-grant requests, etc.
40-
*
41-
*/
43+
* Specifies if cookies should be sent with access-token requests, refresh-token requests,
44+
* custom-grant requests, etc.
45+
*
46+
*/
4247
sendCookiesInRequests?: boolean;
4348
}
4449

@@ -49,9 +54,9 @@ export interface WellKnownAuthClientConfig extends DefaultAuthClientConfig {
4954

5055
export interface ServerOriginAuthClientConfig extends DefaultAuthClientConfig {
5156
/**
52-
* The asgardeo root domain url with the organization.
53-
* @deprecated Use `baseUrl` instead, this will be removed in the next version bump 2.x.x.
54-
*/
57+
* The asgardeo root domain url with the organization.
58+
* @deprecated Use `baseUrl` instead, this will be removed in the next version bump 2.0.0.
59+
*/
5560
serverOrigin: string;
5661
endpoints?: Partial<OIDCEndpoints>;
5762
}

lib/src/models/oidc-provider-meta-data.ts

+6
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,10 @@ export interface OIDCEndpoints {
269269
checkSessionIframe: string;
270270
endSessionEndpoint: string;
271271
issuer: string;
272+
/**
273+
* The well known endpoint path.
274+
* @deprecated This will be removed in the next version bump 2.0.0
275+
* as this is already defined in config.wellKnownEndpoint.
276+
*/
277+
wellKnownEndpoint?: string;
272278
}

0 commit comments

Comments
 (0)