mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-14 10:18:23 +00:00
fix(ui): potential fix for okta login, clear state for avoid login errors (#20379)
* fix(ui): okta login clear state for avoid errors * add fallback option
This commit is contained in:
parent
d317081460
commit
fc30e69442
@ -47,6 +47,10 @@ export const OktaAuthProvider: FunctionComponent<Props> = ({
|
|||||||
tokenManager: {
|
tokenManager: {
|
||||||
autoRenew: false,
|
autoRenew: false,
|
||||||
},
|
},
|
||||||
|
cookies: {
|
||||||
|
secure: true,
|
||||||
|
sameSite: 'none',
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
[clientId, issuer, redirectUri, scopes, pkce]
|
[clientId, issuer, redirectUri, scopes, pkce]
|
||||||
);
|
);
|
||||||
@ -55,7 +59,21 @@ export const OktaAuthProvider: FunctionComponent<Props> = ({
|
|||||||
await oktaAuth.signInWithRedirect();
|
await oktaAuth.signInWithRedirect();
|
||||||
};
|
};
|
||||||
|
|
||||||
const restoreOriginalUri = useCallback(async (_oktaAuth: OktaAuth) => {
|
const customAuthHandler = async () => {
|
||||||
|
const previousAuthState = oktaAuth.authStateManager.getPreviousAuthState();
|
||||||
|
if (!previousAuthState?.isAuthenticated) {
|
||||||
|
// Clear storage before triggering login
|
||||||
|
oktaAuth.tokenManager.clear();
|
||||||
|
await oktaAuth.signOut();
|
||||||
|
// App initialization stage
|
||||||
|
await triggerLogin();
|
||||||
|
} else {
|
||||||
|
// Ask the user to trigger the login process during token autoRenew process
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const restoreOriginalUri = useCallback(
|
||||||
|
async (_oktaAuth: OktaAuth) => {
|
||||||
const idToken = _oktaAuth.getIdToken() ?? '';
|
const idToken = _oktaAuth.getIdToken() ?? '';
|
||||||
const scopes =
|
const scopes =
|
||||||
_oktaAuth.authStateManager.getAuthState()?.idToken?.scopes.join() || '';
|
_oktaAuth.authStateManager.getAuthState()?.idToken?.scopes.join() || '';
|
||||||
@ -77,21 +95,15 @@ export const OktaAuthProvider: FunctionComponent<Props> = ({
|
|||||||
};
|
};
|
||||||
onLoginSuccess(user);
|
onLoginSuccess(user);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(async (err) => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
// Redirect to login on error
|
||||||
|
await customAuthHandler();
|
||||||
});
|
});
|
||||||
}, []);
|
},
|
||||||
|
[onLoginSuccess]
|
||||||
const customAuthHandler = async () => {
|
);
|
||||||
const previousAuthState = oktaAuth.authStateManager.getPreviousAuthState();
|
|
||||||
if (!previousAuthState || !previousAuthState.isAuthenticated) {
|
|
||||||
// App initialization stage
|
|
||||||
await triggerLogin();
|
|
||||||
} else {
|
|
||||||
// Ask the user to trigger the login process during token autoRenew process
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Security
|
<Security
|
||||||
|
Loading…
x
Reference in New Issue
Block a user