Properly save undefined id tokens from OIDC login (#33345)

* Properly save `undefined` id tokens from OIDC login

* Fix tests

* Fix tests again

* Fix lints
This commit is contained in:
Ginger
2026-05-01 09:31:34 -04:00
committed by GitHub
parent 244a2ca011
commit bd369a5109
3 changed files with 16 additions and 3 deletions
+1 -1
View File
@@ -86,7 +86,7 @@ type CompleteOidcLoginResponse = {
// refreshToken gained from OIDC token issuer, when falsy token cannot be refreshed
refreshToken?: string;
// idToken gained from OIDC token issuer
idToken: string;
idToken?: string;
// this client's id as registered with the OIDC issuer
clientId: string;
// issuer used during authentication
@@ -25,10 +25,16 @@ const idTokenClaimsStorageKey = "mx_oidc_id_token_claims";
* @param idToken
* @param idTokenClaims
*/
export const persistOidcAuthenticatedSettings = (clientId: string, issuer: string, idToken: string): void => {
export const persistOidcAuthenticatedSettings = (
clientId: string,
issuer: string,
idToken: string | undefined,
): void => {
localStorage.setItem(clientIdStorageKey, clientId);
localStorage.setItem(tokenIssuerStorageKey, issuer);
localStorage.setItem(idTokenStorageKey, idToken);
if (idToken) {
localStorage.setItem(idTokenStorageKey, idToken);
}
};
/**
@@ -48,6 +48,13 @@ describe("persist OIDC settings", () => {
expect(localStorage.setItem).toHaveBeenCalledWith("mx_oidc_token_issuer", issuer);
expect(localStorage.setItem).toHaveBeenCalledWith("mx_oidc_id_token", idToken);
});
it("should not set idToken in localStorage when idToken is undefined", () => {
persistOidcAuthenticatedSettings(clientId, issuer, undefined);
expect(localStorage.setItem).toHaveBeenCalledWith("mx_oidc_client_id", clientId);
expect(localStorage.setItem).toHaveBeenCalledWith("mx_oidc_token_issuer", issuer);
expect(localStorage.getItem("mx_oidc_id_token")).toBeFalsy();
});
});
describe("getStoredOidcTokenIssuer()", () => {