Skip to content

Commit b7fb3c4

Browse files
authored
Merge pull request #256 from kaviththiranga/master
Support custom params for token request via sign-in method
2 parents 9769b04 + 844637b commit b7fb3c4

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ auth.getAuthorizationURL(config).then((url)=>{
415415
### requestAccessToken
416416

417417
```TypeScript
418-
requestAccessToken(authorizationCode: string, sessionState: string, state: string, userID?: string): Promise<TokenResponse>
418+
requestAccessToken(authorizationCode: string, sessionState: string, state: string, userID?: string, tokenRequestConfig: { params: Record<string, unknown> }): Promise<TokenResponse>
419419
```
420420

421421
#### Arguments
@@ -435,6 +435,18 @@ requestAccessToken(authorizationCode: string, sessionState: string, state: strin
435435

436436
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here to request an access token specific to that user. This can be useful when this SDK is used in backend applications.
437437

438+
5. tokenRequestConfig: `object` (optional)
439+
440+
An optional configuration object that allows you to augment the token request.
441+
442+
- `params` (Mandatory): Key-value pairs to be sent as additional parameters in the token request payload.
443+
444+
445+
```TypeScript
446+
tokenRequestConfig: {
447+
params: Record<string, unknown>
448+
}
449+
```
438450
#### Returns
439451

440452
A Promise that resolves with the [`TokenResponse`](#TokenResponse) object.

lib/src/client.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,19 @@ export class AsgardeoAuthClient<T> {
283283
authorizationCode: string,
284284
sessionState: string,
285285
state: string,
286-
userID?: string
286+
userID?: string,
287+
tokenRequestConfig?: {
288+
params: Record<string, unknown>
289+
}
287290
): Promise<TokenResponse> {
288291
if (await this._dataLayer.getTemporaryDataParameter(OP_CONFIG_INITIATED)) {
289-
return this._authenticationCore.requestAccessToken(authorizationCode, sessionState, state, userID);
292+
return this._authenticationCore.requestAccessToken(authorizationCode, sessionState,
293+
state, userID, tokenRequestConfig);
290294
}
291295

292296
return this._authenticationCore.getOIDCProviderMetaData(false).then(() => {
293-
return this._authenticationCore.requestAccessToken(authorizationCode, sessionState, state, userID);
297+
return this._authenticationCore.requestAccessToken(authorizationCode, sessionState,
298+
state, userID, tokenRequestConfig);
294299
});
295300
}
296301

lib/src/core/authentication-core.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ export class AuthenticationCore<T> {
165165
authorizationCode: string,
166166
sessionState: string,
167167
state: string,
168-
userID?: string
168+
userID?: string,
169+
tokenRequestConfig?: {
170+
params: Record<string, unknown>
171+
}
169172
): Promise<TokenResponse> {
170173
const tokenEndpoint: string | undefined = (await this._oidcProviderMetaData()).token_endpoint;
171174
const configData: StrictAuthClientConfig = await this._config();
@@ -197,6 +200,12 @@ export class AuthenticationCore<T> {
197200
body.set("grant_type", "authorization_code");
198201
body.set("redirect_uri", configData.signInRedirectURL);
199202

203+
if (tokenRequestConfig?.params) {
204+
Object.entries(tokenRequestConfig.params).forEach(([ key, value ]: [key: string, value: unknown]) => {
205+
body.append(key, value as string);
206+
});
207+
}
208+
200209
if (configData.enablePKCE) {
201210
body.set(
202211
"code_verifier", `${await this._dataLayer.getTemporaryDataParameter(

0 commit comments

Comments
 (0)