mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
feat: OIDC redirect flag (#8944)
This commit is contained in:
parent
87d03e8270
commit
9de96c8004
@ -6,13 +6,26 @@ import LockRounded from '@mui/icons-material/LockRounded';
|
||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||
import type { IAuthOptions } from 'hooks/api/getters/useAuth/useAuthEndpoint';
|
||||
import { SSO_LOGIN_BUTTON } from 'utils/testIds';
|
||||
import useQueryParams from 'hooks/useQueryParams';
|
||||
import { useUiFlag } from 'hooks/useUiFlag';
|
||||
|
||||
interface IAuthOptionProps {
|
||||
options?: IAuthOptions[];
|
||||
}
|
||||
|
||||
function addOrOverwriteRedirect(path: string, redirectValue: string): string {
|
||||
const [basePath, queryString = ''] = path.split('?');
|
||||
const params = new URLSearchParams(queryString);
|
||||
params.set('redirect', redirectValue);
|
||||
return `${basePath}?${params.toString()}`;
|
||||
}
|
||||
|
||||
const AuthOptions = ({ options }: IAuthOptionProps) => {
|
||||
const { classes: themeStyles } = useThemeStyles();
|
||||
const oidcRedirectEnabled = useUiFlag('oidcRedirect');
|
||||
const query = useQueryParams();
|
||||
const redirectPath = (oidcRedirectEnabled && query.get('redirect')) || '';
|
||||
|
||||
return (
|
||||
<>
|
||||
{options?.map((o) => (
|
||||
@ -27,7 +40,11 @@ const AuthOptions = ({ options }: IAuthOptionProps) => {
|
||||
color='primary'
|
||||
data-loading
|
||||
variant='outlined'
|
||||
href={o.path}
|
||||
href={
|
||||
redirectPath
|
||||
? addOrOverwriteRedirect(o.path, redirectPath)
|
||||
: o.path
|
||||
}
|
||||
size='small'
|
||||
data-testid={`${SSO_LOGIN_BUTTON}-${o.type}`}
|
||||
style={{
|
||||
|
@ -94,6 +94,7 @@ export type UiFlags = {
|
||||
showUserDeviceCount?: boolean;
|
||||
flagOverviewRedesign?: boolean;
|
||||
licensedUsers?: boolean;
|
||||
oidcRedirect?: boolean;
|
||||
};
|
||||
|
||||
export interface IVersionInfo {
|
||||
|
@ -61,7 +61,8 @@ export type IFlagKey =
|
||||
| 'memorizeStats'
|
||||
| 'licensedUsers'
|
||||
| 'streaming'
|
||||
| 'etagVariant';
|
||||
| 'etagVariant'
|
||||
| 'oidcRedirect';
|
||||
|
||||
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;
|
||||
|
||||
@ -290,6 +291,10 @@ const flags: IFlags = {
|
||||
feature_enabled: false,
|
||||
enabled: false,
|
||||
},
|
||||
oidcRedirect: parseEnvVarBoolean(
|
||||
process.env.UNLEASH_EXPERIMENTAL_OIDC_REDIRECT,
|
||||
false,
|
||||
),
|
||||
};
|
||||
|
||||
export const defaultExperimentalOptions: IExperimentalOptions = {
|
||||
|
Loading…
Reference in New Issue
Block a user