Fix OIDC bugs due to amnesiac stores forgetting OIDC issuer & other data (#12166)
* Fix OIDC bugs due to amnesiac stores forgetting OIDC issuer & other data Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
11096b207a
commit
4e68b91515
4 changed files with 33 additions and 51 deletions
|
@ -21,7 +21,7 @@ const tokenIssuerStorageKey = "mx_oidc_token_issuer";
|
|||
const idTokenClaimsStorageKey = "mx_oidc_id_token_claims";
|
||||
|
||||
/**
|
||||
* Persists oidc clientId and issuer in session storage
|
||||
* Persists oidc clientId and issuer in local storage
|
||||
* Only set after successful authentication
|
||||
* @param clientId
|
||||
* @param issuer
|
||||
|
@ -31,27 +31,27 @@ export const persistOidcAuthenticatedSettings = (
|
|||
issuer: string,
|
||||
idTokenClaims: IdTokenClaims,
|
||||
): void => {
|
||||
sessionStorage.setItem(clientIdStorageKey, clientId);
|
||||
sessionStorage.setItem(tokenIssuerStorageKey, issuer);
|
||||
sessionStorage.setItem(idTokenClaimsStorageKey, JSON.stringify(idTokenClaims));
|
||||
localStorage.setItem(clientIdStorageKey, clientId);
|
||||
localStorage.setItem(tokenIssuerStorageKey, issuer);
|
||||
localStorage.setItem(idTokenClaimsStorageKey, JSON.stringify(idTokenClaims));
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve stored oidc issuer from session storage
|
||||
* Retrieve stored oidc issuer from local storage
|
||||
* When user has token from OIDC issuer, this will be set
|
||||
* @returns issuer or undefined
|
||||
*/
|
||||
export const getStoredOidcTokenIssuer = (): string | undefined => {
|
||||
return sessionStorage.getItem(tokenIssuerStorageKey) ?? undefined;
|
||||
return localStorage.getItem(tokenIssuerStorageKey) ?? undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves stored oidc client id from session storage
|
||||
* Retrieves stored oidc client id from local storage
|
||||
* @returns clientId
|
||||
* @throws when clientId is not found in session storage
|
||||
* @throws when clientId is not found in local storage
|
||||
*/
|
||||
export const getStoredOidcClientId = (): string => {
|
||||
const clientId = sessionStorage.getItem(clientIdStorageKey);
|
||||
const clientId = localStorage.getItem(clientIdStorageKey);
|
||||
if (!clientId) {
|
||||
throw new Error("Oidc client id not found in storage");
|
||||
}
|
||||
|
@ -59,11 +59,11 @@ export const getStoredOidcClientId = (): string => {
|
|||
};
|
||||
|
||||
/**
|
||||
* Retrieve stored id token claims from session storage
|
||||
* Retrieve stored id token claims from local storage
|
||||
* @returns idtokenclaims or undefined
|
||||
*/
|
||||
export const getStoredOidcIdTokenClaims = (): IdTokenClaims | undefined => {
|
||||
const idTokenClaims = sessionStorage.getItem(idTokenClaimsStorageKey);
|
||||
const idTokenClaims = localStorage.getItem(idTokenClaimsStorageKey);
|
||||
if (!idTokenClaims) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue