fix(ui): refresh token for basic auth (#7757)

This commit is contained in:
Chirag Madlani 2022-09-28 11:30:38 +05:30 committed by GitHub
parent b075ed018d
commit 6c2f6089c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 42 deletions

View File

@ -17,7 +17,10 @@ import React, {
ReactNode,
useImperativeHandle,
} from 'react';
import { getAccessTokenOnExpiry } from '../../axiosAPIs/auth-API';
import {
AccessTokenResponse,
getAccessTokenOnExpiry,
} from '../../axiosAPIs/auth-API';
import { AuthTypes } from '../../enums/signin.enum';
import localState from '../../utils/LocalStorageUtils';
import { useAuthContext } from '../auth-provider/AuthProvider';
@ -31,42 +34,31 @@ const BasicAuthenticator = forwardRef(
({ children }: BasicAuthenticatorInterface, ref) => {
const { handleLogout } = useBasicAuth();
const { setIsAuthenticated, authConfig } = useAuthContext();
const handleSilentSignIn = async (): Promise<AccessTokenResponse> => {
const refreshToken = localState.getRefreshToken();
if (authConfig.provider !== AuthTypes.BASIC) {
Promise.reject('AuthProvider is not Basic');
}
const response = await getAccessTokenOnExpiry({
refreshToken: refreshToken as string,
});
localState.setRefreshToken(response.refreshToken);
localState.setOidcToken(response.accessToken);
return Promise.resolve(response);
};
useImperativeHandle(ref, () => ({
invokeLogout() {
handleLogout();
setIsAuthenticated(false);
},
renewIdToken() {
let idToken = '';
const refreshToken = localState.getRefreshToken();
if (authConfig && authConfig.provider !== undefined) {
return new Promise((resolve, reject) => {
const { provider } = authConfig;
if (provider === AuthTypes.BASIC) {
getAccessTokenOnExpiry({
refreshToken: refreshToken as string,
})
.then((res) => {
idToken = res.accessToken;
localState.setOidcToken(res.accessToken);
resolve(idToken);
})
.catch((err) => {
reject(
`Error while renewing id token from Basic Auth: ${err.message}`
);
});
} else {
reject(
`Auth Provider ${provider} not supported for renewing tokens.`
);
}
});
} else {
return Promise.reject(
'Cannot renew id token. Authentication Provider is not present.'
);
}
return handleSilentSignIn();
},
}));

View File

@ -18,7 +18,7 @@ import { PasswordResetRequest } from '../generated/auth/passwordResetRequest';
import { RegistrationRequest } from '../generated/auth/registrationRequest';
import { TokenRefreshRequest } from '../generated/auth/tokenRefreshRequest';
interface AccessTokenResponse {
export interface AccessTokenResponse {
accessToken: string;
refreshToken: string;
tokenType: string;

View File

@ -45,7 +45,7 @@ const ForgotPassword = () => {
<SVGIcons alt="OpenMetadata Logo" icon={Icons.LOGO} width="152" />
</Col>
<Col className="flex-center text-center mt-8" span={24}>
<Typography.Text strong>
<Typography.Text className="tw-text-xl text-semi-bold tw-text-grey-muted">
Enter your registered email to receive password reset link
</Typography.Text>
</Col>

View File

@ -178,9 +178,9 @@ const SigninPage = () => {
'sso-container': !isAuthProviderBasic,
})}>
<SVGIcons alt="OpenMetadata Logo" icon={Icons.LOGO} width="152" />
<Typography.Text strong className="mt-8 tw-mx-auto tw-text-xl w-83">
Centralized Metadata Store, Discover, <br />
Collaborate and get your Data Right
<Typography.Text className="mt-8 w-80 tw-text-xl text-semi-bold tw-text-grey-muted">
Centralized Metadata Store, Discover, Collaborate and get your
Data Right
</Typography.Text>
{isAuthProviderBasic ? (

View File

@ -104,7 +104,9 @@ const ResetPassword = () => {
</Col>
<Col className="mt-12 text-center" span={24}>
<Typography.Title level={5}>Reset your Password</Typography.Title>
<Typography.Text className="tw-text-xl text-semi-bold tw-text-grey-muted">
Reset your Password
</Typography.Text>
</Col>
<Col span={24}>

View File

@ -72,13 +72,13 @@ const BasicSignUp = () => {
<div className="tw-w-5/12">
<div className="mt-4 tw-text-center flex-center flex-col">
<SVGIcons alt="OpenMetadata Logo" icon={Icons.LOGO} width="152" />
<Typography.Text strong className="mt-8 tw-mx-auto tw-text-xl w-83">
Centralized Metadata Store, Discover, <br />
Collaborate and get your Data Right
<Typography.Text className="mt-8 w-80 tw-text-xl text-semi-bold tw-text-grey-muted">
Centralized Metadata Store, Discover, Collaborate and get your
Data Right
</Typography.Text>
{isAuthProviderBasic ? (
<div className="m-t-lg" style={{ width: '334px' }}>
<div style={{ width: '334px' }}>
<Row>
<Col span={24}>
<>
@ -157,7 +157,7 @@ const BasicSignUp = () => {
Create Account
</Button>
<Divider className="w-min-0 w-max-200 mt-8 mb-12 justify-center">
<Divider className="w-min-0 mt-8 mb-12 justify-center">
<Typography.Text type="secondary">or</Typography.Text>
</Divider>

View File

@ -52,6 +52,9 @@
margin-right: auto;
margin-left: auto;
}
.text-semi-bold {
font-weight: 500;
}
.text-center {
text-align: center;
}

View File

@ -271,3 +271,7 @@
position: absolute;
right: 15px;
}
.w-80 {
width: 80%;
}