Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom params for token request #234

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading