Skip to content

Commit

Permalink
feat: OIDC redirect flag (#8944)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Dec 10, 2024
1 parent 87d03e8 commit 9de96c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
19 changes: 18 additions & 1 deletion frontend/src/component/user/common/AuthOptions/AuthOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
Expand All @@ -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={{
Expand Down
1 change: 1 addition & 0 deletions frontend/src/interfaces/uiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export type UiFlags = {
showUserDeviceCount?: boolean;
flagOverviewRedesign?: boolean;
licensedUsers?: boolean;
oidcRedirect?: boolean;
};

export interface IVersionInfo {
Expand Down
7 changes: 6 additions & 1 deletion src/lib/types/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export type IFlagKey =
| 'memorizeStats'
| 'licensedUsers'
| 'streaming'
| 'etagVariant';
| 'etagVariant'
| 'oidcRedirect';

export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;

Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 9de96c8

Please sign in to comment.