Skip to content

Commit

Permalink
Merge pull request #234 from kaviththiranga/main
Browse files Browse the repository at this point in the history
Support custom params for token request
  • Loading branch information
brionmario authored Jul 29, 2024
2 parents 54536e1 + 371b679 commit 8d6831a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
14 changes: 13 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,10 @@ signIn(
authorizationCode?: string,
sessionState?: string,
authState?: string,
callback?: (response: BasicUserInfo) => void
callback?: (response: BasicUserInfo) => void,
tokenRequestConfig?: {
params: Record<string, unknown>
}
);
```
Expand All @@ -348,6 +351,15 @@ signIn(
The `signIn` method can be passed the state parameter as an argument, which will be used to obtain the token during the token-request phase of the method.
5. **callback?**: (response: [`BasicUserInfo`](#basicuserinfo)) => `void`
A callback function that fires when sign-in is successful. The callback function takes an object of type [`BasicUserInfo`](#basicuserinfo) as an argument.
6. **tokenRequestConfig?**: `object` (optional)
An optional configuration object that allows you to augment the token request.
- `params` (Mandatory): Key-value pairs to be sent as additional parameters in the token request payload.
```TypeScript
tokenRequestConfig: {
params: Record<string, unknown>
}
```
The `sign-in` hook is used to fire a callback function after signing out is successful. Check the [`on()`](#on) section for more information.
#### Example
Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"author": "WSO2",
"license": "Apache-2.0",
"dependencies": {
"@asgardeo/auth-spa": "^3.0.7"
"@asgardeo/auth-spa": "^3.1.0"
},
"devDependencies": {
"@babel/cli": "^7.19.3",
Expand Down
7 changes: 5 additions & 2 deletions lib/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ class AuthAPI {
authorizationCode: string,
sessionState: string,
authState?: string,
callback?: (response: BasicUserInfo) => void
callback?: (response: BasicUserInfo) => void,
tokenRequestConfig?: {
params: Record<string, unknown>
}
): Promise<BasicUserInfo> {
return this._client
.signIn(config, authorizationCode, sessionState, authState)
.signIn(config, authorizationCode, sessionState, authState, tokenRequestConfig)
.then(async (response: BasicUserInfo) => {
if (!response) {
return;
Expand Down
8 changes: 6 additions & 2 deletions lib/src/authenticate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
authorizationCode?: string,
sessionState?: string,
authState?: string,
callback?: (response: BasicUserInfo) => void
callback?: (response: BasicUserInfo) => void,
tokenRequestConfig?: {
params: Record<string, unknown>
}
): Promise<BasicUserInfo> => {
try {
setError(null);
Expand All @@ -96,7 +99,8 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
authorizationCode,
sessionState,
authState,
callback
callback,
tokenRequestConfig
);
} catch (error) {
return Promise.reject(error);
Expand Down
5 changes: 4 additions & 1 deletion lib/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ export interface AuthContextInterface {
authorizationCode?: string,
sessionState?: string,
state?: string,
callback?: (response: BasicUserInfo) => void
callback?: (response: BasicUserInfo) => void,
tokenRequestConfig?: {
params: Record<string, unknown>
}
) => Promise<BasicUserInfo>;
signOut: (callback?: (response: boolean) => void) => Promise<boolean>;
getBasicUserInfo(): Promise<BasicUserInfo>;
Expand Down

0 comments on commit 8d6831a

Please sign in to comment.