Skip to content

Commit 3452b9d

Browse files
committed
feat: add getDecodedIdToken function to AsgardeoContext and integrate it in AsgardeoProvider
1 parent faadcad commit 3452b9d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/react/src/contexts/Asgardeo/AsgardeoContext.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
import {Context, createContext} from 'react';
20-
import {HttpRequestConfig, HttpResponse, Organization, SignInOptions} from '@asgardeo/browser';
20+
import {HttpRequestConfig, HttpResponse, IdToken, Organization, SignInOptions} from '@asgardeo/browser';
2121
import AsgardeoReactClient from '../../AsgardeoReactClient';
2222

2323
/**
@@ -89,6 +89,14 @@ export type AsgardeoContextProps = {
8989
* signInOptions: { prompt: "login", fidp: "OrganizationSSO" }
9090
*/
9191
signInOptions?: SignInOptions;
92+
/**
93+
* Function to retrieve the decoded ID token.
94+
* This function decodes the ID token and returns its payload.
95+
* It can be used to access user claims and other information contained in the ID token.
96+
*
97+
* @returns A promise that resolves to the decoded ID token payload.
98+
*/
99+
getDecodedIdToken?: () => Promise<IdToken>;
92100
};
93101

94102
/**
@@ -115,6 +123,7 @@ const AsgardeoContext: Context<AsgardeoContextProps | null> = createContext<null
115123
requestAll: () => null,
116124
},
117125
signInOptions: {},
126+
getDecodedIdToken: null,
118127
});
119128

120129
AsgardeoContext.displayName = 'AsgardeoContext';

packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
395395
request: asgardeo.request.bind(asgardeo),
396396
requestAll: asgardeo.requestAll.bind(asgardeo),
397397
},
398-
signInOptions
398+
signInOptions,
399+
getDecodedIdToken: asgardeo.getDecodedIdToken.bind(asgardeo),
399400
}),
400401
[
401402
applicationId,
@@ -412,7 +413,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
412413
signInSilently,
413414
user,
414415
asgardeo,
415-
signInOptions
416+
signInOptions,
416417
],
417418
);
418419

0 commit comments

Comments
 (0)