Skip to content

Commit 2a6cef6

Browse files
authored
Merge pull request #122 from brionmario/feat-addtional-auth-params
feat: expose `getDecodedIdToken` from the public API
2 parents 17dca44 + f01f421 commit 2a6cef6

File tree

9 files changed

+44
-11
lines changed

9 files changed

+44
-11
lines changed

.changeset/gold-tires-hug.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@asgardeo/browser': patch
3+
'@asgardeo/javascript': patch
4+
'@asgardeo/react': patch
5+
---
6+
7+
Expose `getDecodedIdToken` from the public API

packages/browser/src/__legacy__/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import {SPAUtils} from './utils';
5353
const DefaultConfig: Partial<AuthClientConfig<Config>> = {
5454
autoLogoutOnTokenRefreshError: false,
5555
checkSessionInterval: 3,
56-
enableOIDCSessionManagement: false,
56+
syncSession: false,
5757
periodicTokenRefresh: false,
5858
sessionRefreshInterval: 300,
5959
storage: BrowserStorage.SessionStorage,

packages/browser/src/__legacy__/clients/main-thread-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ export const MainThreadClient = async (
406406
await _authenticationClient.reInitialize(config);
407407

408408
// Re-initiates check session if the check session endpoint is updated.
409-
if (config.enableOIDCSessionManagement && isCheckSessionIframeDifferent) {
409+
if (config.syncSession && isCheckSessionIframeDifferent) {
410410
_sessionManagementHelper.reset();
411411

412412
checkSession();

packages/browser/src/__legacy__/clients/web-worker-client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ export const WebWorkerClient = async (
506506
SPAUtils.setSignOutURL(url, config.clientId, instanceID);
507507

508508
// Enable OIDC Sessions Management only if it is set to true in the config.
509-
if (config.enableOIDCSessionManagement) {
509+
if (config.syncSession) {
510510
checkSession();
511511
}
512512

@@ -534,7 +534,7 @@ export const WebWorkerClient = async (
534534
await startAutoRefreshToken();
535535

536536
// Enable OIDC Sessions Management only if it is set to true in the config.
537-
if (config.enableOIDCSessionManagement) {
537+
if (config.syncSession) {
538538
checkSession();
539539
}
540540

@@ -829,7 +829,7 @@ export const WebWorkerClient = async (
829829
await communicate<Partial<AuthClientConfig<WebWorkerClientConfig>>, void>(message);
830830

831831
// Re-initiates check session if the check session endpoint is updated.
832-
if (config.enableOIDCSessionManagement && isCheckSessionIframeDifferent) {
832+
if (config.syncSession && isCheckSessionIframeDifferent) {
833833
_sessionManagementHelper.reset();
834834

835835
checkSession();

packages/browser/src/__legacy__/helpers/authentication-helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ export class AuthenticationHelper<T extends MainThreadClientConfig | WebWorkerCl
480480
}
481481

482482
// Enable OIDC Sessions Management only if it is set to true in the config.
483-
if (checkSession && typeof checkSession === 'function' && config.enableOIDCSessionManagement) {
483+
if (checkSession && typeof checkSession === 'function' && config.syncSession) {
484484
checkSession();
485485
}
486486
} else {
@@ -606,7 +606,7 @@ export class AuthenticationHelper<T extends MainThreadClientConfig | WebWorkerCl
606606
this._spaHelper.refreshAccessTokenAutomatically(this);
607607

608608
// Enable OIDC Sessions Management only if it is set to true in the config.
609-
if (config.enableOIDCSessionManagement) {
609+
if (config.syncSession) {
610610
checkSession();
611611
}
612612

packages/browser/src/__legacy__/models/client-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface SPAConfig {
2525
* @remarks If the consumer app the OP is hosted in different domains,
2626
* third party cookies has to be enabled for this to work properly.
2727
*/
28-
enableOIDCSessionManagement?: boolean;
28+
syncSession?: boolean;
2929
checkSessionInterval?: number;
3030
sessionRefreshInterval?: number;
3131
resourceServerURLs?: string[];

packages/javascript/src/models/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ export interface BaseConfig<T = unknown> extends WithPreferences {
185185
* @see {@link SignUpOptions} for more details.
186186
*/
187187
signUpOptions?: SignUpOptions;
188+
189+
/**
190+
* Flag to indicate whether the Application session should be synchronized with the IdP session.
191+
* @remarks This uses the OIDC iframe base session management feature to keep the application session in sync with the IdP session.
192+
* WARNING: This may not work in all browsers due to 3rd party cookie restrictions.
193+
* It is recommended to use this feature only if you are aware of the implications and have tested it in your target browsers.
194+
* If you are not sure, it is safer to leave this option as `false`.
195+
* @example
196+
* syncSession: true
197+
* @see {@link https://openid.net/specs/openid-connect-session-management-1_0.html#IframeBasedSessionManagement}
198+
*/
199+
syncSession?: boolean;
188200
}
189201

190202
export interface WithPreferences {

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
5757
organizationHandle,
5858
applicationId,
5959
signInOptions,
60+
syncSession,
6061
...rest
6162
}: PropsWithChildren<AsgardeoProviderProps>): ReactElement => {
6263
const reRenderCheckRef: RefObject<boolean> = useRef(false);
@@ -83,6 +84,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
8384
signUpUrl,
8485
signInUrl,
8586
signInOptions,
87+
syncSession,
8688
...rest,
8789
});
8890

@@ -395,7 +397,9 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
395397
request: asgardeo.request.bind(asgardeo),
396398
requestAll: asgardeo.requestAll.bind(asgardeo),
397399
},
398-
signInOptions
400+
signInOptions,
401+
getDecodedIdToken: asgardeo.getDecodedIdToken.bind(asgardeo),
402+
syncSession,
399403
}),
400404
[
401405
applicationId,
@@ -412,7 +416,8 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
412416
signInSilently,
413417
user,
414418
asgardeo,
415-
signInOptions
419+
signInOptions,
420+
syncSession,
416421
],
417422
);
418423

0 commit comments

Comments
 (0)