Skip to content

Commit

Permalink
Support custom params for token request
Browse files Browse the repository at this point in the history
  • Loading branch information
kaviththiranga committed Jul 24, 2024
1 parent 9769b04 commit 81485cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 8 additions & 3 deletions lib/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,19 @@ export class AsgardeoAuthClient<T> {
authorizationCode: string,
sessionState: string,
state: string,
userID?: string
userID?: string,
tokenRequestConfig?: {
params: Record<string, unknown>
}
): Promise<TokenResponse> {
if (await this._dataLayer.getTemporaryDataParameter(OP_CONFIG_INITIATED)) {
return this._authenticationCore.requestAccessToken(authorizationCode, sessionState, state, userID);
return this._authenticationCore.requestAccessToken(authorizationCode, sessionState,
state, userID, tokenRequestConfig);
}

return this._authenticationCore.getOIDCProviderMetaData(false).then(() => {
return this._authenticationCore.requestAccessToken(authorizationCode, sessionState, state, userID);
return this._authenticationCore.requestAccessToken(authorizationCode, sessionState,
state, userID, tokenRequestConfig);
});
}

Expand Down
16 changes: 14 additions & 2 deletions lib/src/core/authentication-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,12 @@ export class AuthenticationCore<T> {
authorizationCode: string,
sessionState: string,
state: string,
userID?: string
userID?: string,
tokenRequestConfig?: {
params: Record<string, unknown>
}
): Promise<TokenResponse> {
const tokenEndpoint: string | undefined = (await this._oidcProviderMetaData()).token_endpoint;
let tokenEndpoint: string | undefined = (await this._oidcProviderMetaData()).token_endpoint;
const configData: StrictAuthClientConfig = await this._config();

if (!tokenEndpoint || tokenEndpoint.trim().length === 0) {
Expand All @@ -179,6 +182,15 @@ export class AuthenticationCore<T> {
);
}

if (tokenRequestConfig && tokenRequestConfig.params) {
const url: URL = new URL(tokenEndpoint);

Object.entries(tokenRequestConfig.params).forEach(([ key, value ]: [key: string, value: unknown]) => {
url.searchParams.append(key, value as string);
});
tokenEndpoint = url.toString();
}

sessionState && (await this._dataLayer.setSessionDataParameter(
SESSION_STATE as keyof SessionData, sessionState, userID));

Expand Down

0 comments on commit 81485cb

Please sign in to comment.