diff --git a/frontend/src/component/user/common/AuthOptions/AuthOptions.tsx b/frontend/src/component/user/common/AuthOptions/AuthOptions.tsx index fc84d8ff24d6..3d6edb8cc9ef 100644 --- a/frontend/src/component/user/common/AuthOptions/AuthOptions.tsx +++ b/frontend/src/component/user/common/AuthOptions/AuthOptions.tsx @@ -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={{ diff --git a/frontend/src/interfaces/uiConfig.ts b/frontend/src/interfaces/uiConfig.ts index 19263be2b3e2..523d82d4affd 100644 --- a/frontend/src/interfaces/uiConfig.ts +++ b/frontend/src/interfaces/uiConfig.ts @@ -94,6 +94,7 @@ export type UiFlags = { showUserDeviceCount?: boolean; flagOverviewRedesign?: boolean; licensedUsers?: boolean; + oidcRedirect?: boolean; }; export interface IVersionInfo { diff --git a/src/lib/types/experimental.ts b/src/lib/types/experimental.ts index 4bea097ec534..493d439efa99 100644 --- a/src/lib/types/experimental.ts +++ b/src/lib/types/experimental.ts @@ -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 = {