fix(ui): disable auto renew for react-okta (#12530)

* fix(ui): disable autorenew for react-okta

* update okta token on renewal
This commit is contained in:
Chirag Madlani 2023-07-21 18:08:29 +05:30 committed by GitHub
parent 977e13d00c
commit 536d1e9e19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 7 deletions

View File

@ -414,7 +414,11 @@ const ExploreV1: React.FC<ExploreProps> = ({
handleSummaryPanelDisplay={handleSummaryPanelDisplay}
isSummaryPanelVisible={showSummaryPanel}
selectedEntityId={entityDetails?.id || ''}
totalValue={searchResults?.hits.total.value ?? 0}
totalValue={
tabCounts?.[searchIndex] ??
searchResults?.hits.total.value ??
0
}
onPaginationChange={onChangePage}
/>
) : (

View File

@ -299,7 +299,14 @@ export const AuthProvider = ({
const { isExpired, timeoutExpiry } = extractDetailsFromToken();
const refreshToken = localState.getRefreshToken();
if (!isExpired && isNumber(timeoutExpiry) && refreshToken) {
// Basic & LDAP renewToken depends on RefreshToken hence adding a check here for the same
const shouldStartExpiry =
refreshToken ||
[AuthTypes.BASIC, AuthTypes.LDAP].indexOf(
authConfig?.provider as AuthTypes
) === -1;
if (!isExpired && isNumber(timeoutExpiry) && shouldStartExpiry) {
// Have 5m buffer before start trying for silent signIn
// If token is about to expire then start silentSignIn
// else just set timer to try for silentSignIn before token expires

View File

@ -35,6 +35,9 @@ export const OktaAuthProvider: FunctionComponent<Props> = ({
redirectUri,
scopes,
pkce,
tokenManager: {
autoRenew: false,
},
});
const triggerLogin = async () => {

View File

@ -64,11 +64,13 @@ const OktaAuthenticator = forwardRef<AuthenticatorRef, Props>(
logout();
},
async renewIdToken() {
await oktaAuth.token.renewTokens();
const idToken = oktaAuth.getIdToken() || '';
localState.setOidcToken(idToken);
const renewToken = await oktaAuth.token.renewTokens();
oktaAuth.tokenManager.setTokens(renewToken);
const newToken =
renewToken?.idToken?.idToken ?? oktaAuth.getIdToken() ?? '';
localState.setOidcToken(newToken);
return Promise.resolve(idToken);
return Promise.resolve(newToken);
},
}));

View File

@ -157,7 +157,7 @@ const SearchedData: React.FC<SearchedDataProps> = ({
{searchResultCards}
<Pagination
hideOnSinglePage
className="text-center"
className="text-center m-b-sm"
current={isNumber(Number(page)) ? Number(page) : 1}
pageSize={
size && isNumber(Number(size))