Skip to content

Commit

Permalink
Add custom params to body of the token request
Browse files Browse the repository at this point in the history
  • Loading branch information
kaviththiranga committed Jul 25, 2024
1 parent 81485cb commit 9f8cea6
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/src/core/authentication-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class AuthenticationCore<T> {
params: Record<string, unknown>
}
): Promise<TokenResponse> {
let tokenEndpoint: string | undefined = (await this._oidcProviderMetaData()).token_endpoint;
const tokenEndpoint: string | undefined = (await this._oidcProviderMetaData()).token_endpoint;
const configData: StrictAuthClientConfig = await this._config();

if (!tokenEndpoint || tokenEndpoint.trim().length === 0) {
Expand All @@ -182,15 +182,6 @@ 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 All @@ -209,6 +200,12 @@ export class AuthenticationCore<T> {
body.set("grant_type", "authorization_code");
body.set("redirect_uri", configData.signInRedirectURL);

if (tokenRequestConfig && tokenRequestConfig.params) {
Object.entries(tokenRequestConfig.params).forEach(([ key, value ]: [key: string, value: unknown]) => {
body.append(key, value as string);
});
}

if (configData.enablePKCE) {
body.set(
"code_verifier", `${await this._dataLayer.getTemporaryDataParameter(
Expand Down

0 comments on commit 9f8cea6

Please sign in to comment.