Skip to content
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
7 changes: 7 additions & 0 deletions .changeset/gold-tires-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@asgardeo/browser': patch
'@asgardeo/javascript': patch
'@asgardeo/react': patch
---

Expose `getDecodedIdToken` from the public API
2 changes: 1 addition & 1 deletion packages/browser/src/__legacy__/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {SPAUtils} from './utils';
const DefaultConfig: Partial<AuthClientConfig<Config>> = {
autoLogoutOnTokenRefreshError: false,
checkSessionInterval: 3,
enableOIDCSessionManagement: false,
syncSession: false,
periodicTokenRefresh: false,
sessionRefreshInterval: 300,
storage: BrowserStorage.SessionStorage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export const MainThreadClient = async (
await _authenticationClient.reInitialize(config);

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

checkSession();
Expand Down
6 changes: 3 additions & 3 deletions packages/browser/src/__legacy__/clients/web-worker-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ export const WebWorkerClient = async (
SPAUtils.setSignOutURL(url, config.clientId, instanceID);

// Enable OIDC Sessions Management only if it is set to true in the config.
if (config.enableOIDCSessionManagement) {
if (config.syncSession) {
checkSession();
}

Expand Down Expand Up @@ -534,7 +534,7 @@ export const WebWorkerClient = async (
await startAutoRefreshToken();

// Enable OIDC Sessions Management only if it is set to true in the config.
if (config.enableOIDCSessionManagement) {
if (config.syncSession) {
checkSession();
}

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

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

checkSession();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ export class AuthenticationHelper<T extends MainThreadClientConfig | WebWorkerCl
}

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

// Enable OIDC Sessions Management only if it is set to true in the config.
if (config.enableOIDCSessionManagement) {
if (config.syncSession) {
checkSession();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/__legacy__/models/client-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface SPAConfig {
* @remarks If the consumer app the OP is hosted in different domains,
* third party cookies has to be enabled for this to work properly.
*/
enableOIDCSessionManagement?: boolean;
syncSession?: boolean;
checkSessionInterval?: number;
sessionRefreshInterval?: number;
resourceServerURLs?: string[];
Expand Down
12 changes: 12 additions & 0 deletions packages/javascript/src/models/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ export interface BaseConfig<T = unknown> extends WithPreferences {
* @see {@link SignUpOptions} for more details.
*/
signUpOptions?: SignUpOptions;

/**
* Flag to indicate whether the Application session should be synchronized with the IdP session.
* @remarks This uses the OIDC iframe base session management feature to keep the application session in sync with the IdP session.
* WARNING: This may not work in all browsers due to 3rd party cookie restrictions.
* It is recommended to use this feature only if you are aware of the implications and have tested it in your target browsers.
* If you are not sure, it is safer to leave this option as `false`.
* @example
* syncSession: true
* @see {@link https://openid.net/specs/openid-connect-session-management-1_0.html#IframeBasedSessionManagement}
*/
syncSession?: boolean;
}

export interface WithPreferences {
Expand Down
11 changes: 10 additions & 1 deletion packages/react/src/contexts/Asgardeo/AsgardeoContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import {Context, createContext} from 'react';
import {HttpRequestConfig, HttpResponse, Organization, SignInOptions} from '@asgardeo/browser';
import {HttpRequestConfig, HttpResponse, IdToken, Organization, SignInOptions} from '@asgardeo/browser';
import AsgardeoReactClient from '../../AsgardeoReactClient';

/**
Expand Down Expand Up @@ -89,6 +89,14 @@ export type AsgardeoContextProps = {
* signInOptions: { prompt: "login", fidp: "OrganizationSSO" }
*/
signInOptions?: SignInOptions;
/**
* Function to retrieve the decoded ID token.
* This function decodes the ID token and returns its payload.
* It can be used to access user claims and other information contained in the ID token.
*
* @returns A promise that resolves to the decoded ID token payload.
*/
getDecodedIdToken?: () => Promise<IdToken>;
};

/**
Expand All @@ -115,6 +123,7 @@ const AsgardeoContext: Context<AsgardeoContextProps | null> = createContext<null
requestAll: () => null,
},
signInOptions: {},
getDecodedIdToken: null,
});

AsgardeoContext.displayName = 'AsgardeoContext';
Expand Down
9 changes: 7 additions & 2 deletions packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
organizationHandle,
applicationId,
signInOptions,
syncSession,
...rest
}: PropsWithChildren<AsgardeoProviderProps>): ReactElement => {
const reRenderCheckRef: RefObject<boolean> = useRef(false);
Expand All @@ -83,6 +84,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
signUpUrl,
signInUrl,
signInOptions,
syncSession,
...rest,
});

Expand Down Expand Up @@ -395,7 +397,9 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
request: asgardeo.request.bind(asgardeo),
requestAll: asgardeo.requestAll.bind(asgardeo),
},
signInOptions
signInOptions,
getDecodedIdToken: asgardeo.getDecodedIdToken.bind(asgardeo),
syncSession,
}),
[
applicationId,
Expand All @@ -412,7 +416,8 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
signInSilently,
user,
asgardeo,
signInOptions
signInOptions,
syncSession,
],
);

Expand Down
Loading