Skip to content

Commit

Permalink
Merge pull request #236 from Yasasr1/use-client-id
Browse files Browse the repository at this point in the history
Send client_id in logout request
  • Loading branch information
Yasasr1 authored Oct 2, 2023
2 parents f1ca1cf + 48a90cc commit 595750c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@ This model has the following attributes.
|`validateIDToken`|Optional| `boolean`|`true`|Allows you to enable/disable JWT ID token validation after obtaining the ID token.|
|`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.|

The `AuthClientConfig<T>` can be extended by passing an interface as the generic type. For example, if you want to add an attribute called `foo` to the config object, you can create an interface called `Bar` and pass that as the generic type into the `AuthClientConfig<T>` interface.

Expand Down
27 changes: 16 additions & 11 deletions lib/src/core/authentication-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,16 +546,6 @@ export class AuthenticationCore<T> {
);
}

const idToken: string = (await this._dataLayer.getSessionData(userID))?.id_token;

if (!idToken || idToken.trim().length === 0) {
throw new AsgardeoAuthException(
"JS-AUTH_CORE-GSOU-NF02",
"ID token not found.",
"No ID token could be found. Either the session information is lost or you have not signed in."
);
}

const callbackURL: string = configData?.signOutRedirectURL ?? configData?.signInRedirectURL;

if (!callbackURL || callbackURL.trim().length === 0) {
Expand All @@ -567,9 +557,24 @@ export class AuthenticationCore<T> {
);
}

let parameter: string = `client_id=${ configData.clientID }`;

if (configData.sendIdTokenInLogoutRequest) {
const idToken: string = (await this._dataLayer.getSessionData(userID))?.id_token;

if (!idToken || idToken.trim().length === 0) {
throw new AsgardeoAuthException(
"JS-AUTH_CORE-GSOU-NF02",
"ID token not found.",
"No ID token could be found. Either the session information is lost or you have not signed in."
);
}
parameter = `id_token_hint=${ idToken }`;
}

const logoutCallback: string =
`${ logoutEndpoint }?` +
`id_token_hint=${ idToken }` +
parameter +
`&post_logout_redirect_uri=${ callbackURL }&state=` +
SIGN_OUT_SUCCESS_PARAM;

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 @@ -40,6 +40,7 @@ export interface DefaultAuthClientConfig {
*
*/
sendCookiesInRequests?: boolean;
sendIdTokenInLogoutRequest?: boolean;
}

export interface WellKnownAuthClientConfig extends DefaultAuthClientConfig {
Expand Down

0 comments on commit 595750c

Please sign in to comment.