mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-01 13:13:10 +00:00
fix(ui): refresh token for basic auth (#7757)
This commit is contained in:
parent
b075ed018d
commit
6c2f6089c7
@ -17,7 +17,10 @@ import React, {
|
|||||||
ReactNode,
|
ReactNode,
|
||||||
useImperativeHandle,
|
useImperativeHandle,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { getAccessTokenOnExpiry } from '../../axiosAPIs/auth-API';
|
import {
|
||||||
|
AccessTokenResponse,
|
||||||
|
getAccessTokenOnExpiry,
|
||||||
|
} from '../../axiosAPIs/auth-API';
|
||||||
import { AuthTypes } from '../../enums/signin.enum';
|
import { AuthTypes } from '../../enums/signin.enum';
|
||||||
import localState from '../../utils/LocalStorageUtils';
|
import localState from '../../utils/LocalStorageUtils';
|
||||||
import { useAuthContext } from '../auth-provider/AuthProvider';
|
import { useAuthContext } from '../auth-provider/AuthProvider';
|
||||||
@ -31,42 +34,31 @@ const BasicAuthenticator = forwardRef(
|
|||||||
({ children }: BasicAuthenticatorInterface, ref) => {
|
({ children }: BasicAuthenticatorInterface, ref) => {
|
||||||
const { handleLogout } = useBasicAuth();
|
const { handleLogout } = useBasicAuth();
|
||||||
const { setIsAuthenticated, authConfig } = useAuthContext();
|
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, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
invokeLogout() {
|
invokeLogout() {
|
||||||
handleLogout();
|
handleLogout();
|
||||||
setIsAuthenticated(false);
|
setIsAuthenticated(false);
|
||||||
},
|
},
|
||||||
renewIdToken() {
|
renewIdToken() {
|
||||||
let idToken = '';
|
return handleSilentSignIn();
|
||||||
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.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import { PasswordResetRequest } from '../generated/auth/passwordResetRequest';
|
|||||||
import { RegistrationRequest } from '../generated/auth/registrationRequest';
|
import { RegistrationRequest } from '../generated/auth/registrationRequest';
|
||||||
import { TokenRefreshRequest } from '../generated/auth/tokenRefreshRequest';
|
import { TokenRefreshRequest } from '../generated/auth/tokenRefreshRequest';
|
||||||
|
|
||||||
interface AccessTokenResponse {
|
export interface AccessTokenResponse {
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
refreshToken: string;
|
refreshToken: string;
|
||||||
tokenType: string;
|
tokenType: string;
|
||||||
|
@ -45,7 +45,7 @@ const ForgotPassword = () => {
|
|||||||
<SVGIcons alt="OpenMetadata Logo" icon={Icons.LOGO} width="152" />
|
<SVGIcons alt="OpenMetadata Logo" icon={Icons.LOGO} width="152" />
|
||||||
</Col>
|
</Col>
|
||||||
<Col className="flex-center text-center mt-8" span={24}>
|
<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
|
Enter your registered email to receive password reset link
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
</Col>
|
</Col>
|
||||||
|
@ -178,9 +178,9 @@ const SigninPage = () => {
|
|||||||
'sso-container': !isAuthProviderBasic,
|
'sso-container': !isAuthProviderBasic,
|
||||||
})}>
|
})}>
|
||||||
<SVGIcons alt="OpenMetadata Logo" icon={Icons.LOGO} width="152" />
|
<SVGIcons alt="OpenMetadata Logo" icon={Icons.LOGO} width="152" />
|
||||||
<Typography.Text strong className="mt-8 tw-mx-auto tw-text-xl w-83">
|
<Typography.Text className="mt-8 w-80 tw-text-xl text-semi-bold tw-text-grey-muted">
|
||||||
Centralized Metadata Store, Discover, <br />
|
Centralized Metadata Store, Discover, Collaborate and get your
|
||||||
Collaborate and get your Data Right
|
Data Right
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
|
||||||
{isAuthProviderBasic ? (
|
{isAuthProviderBasic ? (
|
||||||
|
@ -104,7 +104,9 @@ const ResetPassword = () => {
|
|||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col className="mt-12 text-center" span={24}>
|
<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>
|
||||||
|
|
||||||
<Col span={24}>
|
<Col span={24}>
|
||||||
|
@ -72,13 +72,13 @@ const BasicSignUp = () => {
|
|||||||
<div className="tw-w-5/12">
|
<div className="tw-w-5/12">
|
||||||
<div className="mt-4 tw-text-center flex-center flex-col">
|
<div className="mt-4 tw-text-center flex-center flex-col">
|
||||||
<SVGIcons alt="OpenMetadata Logo" icon={Icons.LOGO} width="152" />
|
<SVGIcons alt="OpenMetadata Logo" icon={Icons.LOGO} width="152" />
|
||||||
<Typography.Text strong className="mt-8 tw-mx-auto tw-text-xl w-83">
|
<Typography.Text className="mt-8 w-80 tw-text-xl text-semi-bold tw-text-grey-muted">
|
||||||
Centralized Metadata Store, Discover, <br />
|
Centralized Metadata Store, Discover, Collaborate and get your
|
||||||
Collaborate and get your Data Right
|
Data Right
|
||||||
</Typography.Text>
|
</Typography.Text>
|
||||||
|
|
||||||
{isAuthProviderBasic ? (
|
{isAuthProviderBasic ? (
|
||||||
<div className="m-t-lg" style={{ width: '334px' }}>
|
<div style={{ width: '334px' }}>
|
||||||
<Row>
|
<Row>
|
||||||
<Col span={24}>
|
<Col span={24}>
|
||||||
<>
|
<>
|
||||||
@ -157,7 +157,7 @@ const BasicSignUp = () => {
|
|||||||
Create Account
|
Create Account
|
||||||
</Button>
|
</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>
|
<Typography.Text type="secondary">or</Typography.Text>
|
||||||
</Divider>
|
</Divider>
|
||||||
|
|
||||||
|
@ -52,6 +52,9 @@
|
|||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
}
|
}
|
||||||
|
.text-semi-bold {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
.text-center {
|
.text-center {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
@ -271,3 +271,7 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
right: 15px;
|
right: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.w-80 {
|
||||||
|
width: 80%;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user