Skip to content

Commit e377c6d

Browse files
committed
fix: use decoder-only approach for ID tokens in getUserFromSession
Removes validation to accept expired ID tokens for user display info. Creates cleaner separation of concerns - validate when storing, decode when reading.
1 parent bc68621 commit e377c6d

File tree

4 files changed

+5
-19
lines changed

4 files changed

+5
-19
lines changed

lib/__tests__/sdk/utilities/token-utils.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe('token-utils', () => {
117117
validationDetails
118118
);
119119

120-
const storedUser = await getUserFromSession(sessionManager, validationDetails);
120+
const storedUser = await getUserFromSession(sessionManager);
121121
const expectedUser = {
122122
family_name: idTokenPayload.family_name,
123123
given_name: idTokenPayload.given_name,

lib/sdk/clients/browser/authcode-with-pkce.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ const createAuthCodeWithPKCEClient = (options: BrowserPKCEClientOptions) => {
114114
if (!(await isAuthenticated())) {
115115
throw new Error('Cannot get user details, no authentication credential found');
116116
}
117-
return (await utilities.getUserFromSession(
118-
sessionManager,
119-
client.tokenValidationDetails
120-
))!;
117+
return (await utilities.getUserFromSession(sessionManager))!;
121118
};
122119

123120
/**

lib/sdk/clients/server/authorization-code.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,7 @@ const createAuthorizationCodeClient = (
139139
if (!(await isAuthenticated(sessionManager))) {
140140
throw new Error('Cannot get user details, no authentication credential found');
141141
}
142-
return (await utilities.getUserFromSession(
143-
sessionManager,
144-
client.tokenValidationDetails
145-
))!;
142+
return (await utilities.getUserFromSession(sessionManager))!;
146143
};
147144

148145
/**

lib/sdk/utilities/token-utils.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,14 @@ export const getAccessToken = async (
111111
* Extracts the user information from the current session returns null if
112112
* the token is not found.
113113
* @param {SessionManager} sessionManager
114-
* @param {TokenValidationDetailsType} validationDetails
115114
* @returns {UserType | null}
116115
*/
117116
export const getUserFromSession = async (
118-
sessionManager: SessionManager,
119-
validationDetails: TokenValidationDetailsType
117+
sessionManager: SessionManager
120118
): Promise<UserType | null> => {
121119
const idTokenString = (await sessionManager.getSessionItem('id_token')) as string;
122-
const validation = await validateToken({
123-
token: idTokenString,
124-
domain: validationDetails.issuer,
125-
});
126-
if (!validation.valid) {
127-
throw new Error('Invalid ID token');
128-
}
129120

121+
// Simply decode the ID token without validation to accept old tokens
130122
const payload: Record<string, unknown> = jwtDecoder(idTokenString) ?? {};
131123
if (Object.keys(payload).length === 0) {
132124
throw new Error('Invalid ID token');

0 commit comments

Comments
 (0)