mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-11-10 09:15:16 +00:00
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:
@@ -86,7 +86,7 @@ type CompleteOidcLoginResponse = {
|
|||||||
// refreshToken gained from OIDC token issuer, when falsy token cannot be refreshed
|
// refreshToken gained from OIDC token issuer, when falsy token cannot be refreshed
|
||||||
refreshToken?: string;
|
refreshToken?: string;
|
||||||
// idToken gained from OIDC token issuer
|
// idToken gained from OIDC token issuer
|
||||||
idToken: string;
|
idToken?: string;
|
||||||
// this client's id as registered with the OIDC issuer
|
// this client's id as registered with the OIDC issuer
|
||||||
clientId: string;
|
clientId: string;
|
||||||
// issuer used during authentication
|
// issuer used during authentication
|
||||||
|
|||||||
@@ -25,10 +25,16 @@ const idTokenClaimsStorageKey = "mx_oidc_id_token_claims";
|
|||||||
* @param idToken
|
* @param idToken
|
||||||
* @param idTokenClaims
|
* @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(clientIdStorageKey, clientId);
|
||||||
localStorage.setItem(tokenIssuerStorageKey, issuer);
|
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_token_issuer", issuer);
|
||||||
expect(localStorage.setItem).toHaveBeenCalledWith("mx_oidc_id_token", idToken);
|
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()", () => {
|
describe("getStoredOidcTokenIssuer()", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user