Skip to content

Commit

Permalink
Merge pull request #247 from dhaura/DP-fix-id-token-issuer-validation
Browse files Browse the repository at this point in the history
Add Functionality Enable or Disable ID Token Issuer Validation
  • Loading branch information
pavinduLakshan authored Dec 12, 2023
2 parents 72ece3f + 2826389 commit 73c9ffa
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ This model has the following attributes.
|`endpoints`|Optional (Required to provide all endpoints, if `wellKnownEndpoint` or `baseUrl` is not provided)| `OIDCEndpoints`|[OIDC Endpoints Default Values](#oidc-endpoints)|The OIDC endpoint URLs. The SDK will try to obtain the endpoint URLS |using the `.well-known` endpoint. If this fails, the SDK will use these endpoint URLs. If this attribute is not set, then the default endpoint URLs will be |used.
|`wellKnownEndpoint`|Optional (Required if `baseUrl` or `endpoints` is not provided)| `string`|`"/oauth2/token/.well-known/openid-configuration"`| The URL of the `.well-known` endpoint.|
|`validateIDToken`|Optional| `boolean`|`true`|Allows you to enable/disable JWT ID token validation after obtaining the ID token.|
|`validateIDTokenIssuer`(optional) | `boolean` | `true` | Allows you to enable/disable JWT ID token issuer validation after obtaining the ID token (This config is applicable only when JWT ID token validation is enabled). |
|`clockTolerance`|Optional| `number`|`60`|Allows you to configure the leeway when validating the id_token.|
|`sendCookiesInRequests`|Optional| `boolean`|`true`|Specifies if cookies should be sent in the requests.|
|`sendIdTokenInLogoutRequest`|Optional| `boolean`|`false`|Specifies if `id_token_hint` parameter should be sent in the logout request instead of the default `client_id` parameter.|
Expand Down
3 changes: 2 additions & 1 deletion lib/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const DefaultConfig: Partial<AuthClientConfig<unknown>> = {
responseMode: ResponseMode.query,
scope: [ OIDC_SCOPE ],
sendCookiesInRequests: true,
validateIDToken: true
validateIDToken: true,
validateIDTokenIssuer: true
};

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/src/helpers/authentication-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ export class AuthenticationHelper<T> {
(await this._config()).clientID,
issuer ?? "",
this._cryptoHelper.decodeIDToken(idToken).sub,
(await this._config()).clockTolerance
(await this._config()).clockTolerance,
(await this._config()).validateIDTokenIssuer ?? true
);
}

Expand Down
14 changes: 12 additions & 2 deletions lib/src/helpers/crypto-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,20 @@ export class CryptoHelper<T = any> {
clientID: string,
issuer: string,
username: string,
clockTolerance: number | undefined
clockTolerance: number | undefined,
validateJwtIssuer: boolean | undefined
): Promise<boolean> {
return this._cryptoUtils
.verifyJwt(idToken, jwk, SUPPORTED_SIGNATURE_ALGORITHMS, clientID, issuer, username, clockTolerance)
.verifyJwt(
idToken,
jwk,
SUPPORTED_SIGNATURE_ALGORITHMS,
clientID,
issuer,
username,
clockTolerance,
validateJwtIssuer
)
.then((response: boolean) => {
if (response) {
return Promise.resolve(true);
Expand Down
1 change: 1 addition & 0 deletions lib/src/models/client-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface DefaultAuthClientConfig {
responseMode?: ResponseMode;
scope?: string[];
validateIDToken?: boolean;
validateIDTokenIssuer?: boolean;
/**
* Allowed leeway for id_tokens (in seconds).
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/src/models/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface CryptoUtils<T = any> {
clientID: string,
issuer: string,
subject: string,
clockTolerance?: number
clockTolerance?: number,
validateJwtIssuer?: boolean
): Promise<boolean>;
}

0 comments on commit 73c9ffa

Please sign in to comment.