Skip to content

Commit

Permalink
feat: make frontend aware that OIDC can be configured through env (#7597
Browse files Browse the repository at this point in the history
)

Co-authored-by: Nuno Góis <[email protected]>
  • Loading branch information
chriswk and nunogois authored Jul 16, 2024
1 parent e43109a commit 7ed1d77
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ interface IAutoCreateFormProps {
value: string | boolean | number | undefined,
) => void;
onUpdateRole: (role: IRole | null) => void;
disabled?: boolean;
}

export const AutoCreateForm = ({
data = { enabled: false, autoCreate: false },
setValue,
onUpdateRole,
disabled = false,
}: IAutoCreateFormProps) => {
const { roles } = useRoles();

Expand Down Expand Up @@ -69,7 +71,7 @@ export const AutoCreateForm = ({
onChange={updateAutoCreate}
name='enabled'
checked={data.autoCreate}
disabled={!data.enabled}
disabled={!data.enabled || disabled}
/>
}
label='Auto-create users'
Expand All @@ -90,7 +92,9 @@ export const AutoCreateForm = ({
roles={roles}
value={resolveRole(data)}
setValue={onUpdateRole}
disabled={!data.autoCreate || !data.enabled}
disabled={
!data.autoCreate || !data.enabled || disabled
}
required
hideDescription
/>
Expand All @@ -110,7 +114,7 @@ export const AutoCreateForm = ({
onChange={updateField}
label='Email domains'
name='emailDomains'
disabled={!data.autoCreate || !data.enabled}
disabled={!data.autoCreate || !data.enabled || disabled}
required={Boolean(data.autoCreate)}
value={data.emailDomains || ''}
placeholder='@company.com, @anotherCompany.com'
Expand Down
39 changes: 33 additions & 6 deletions frontend/src/component/admin/auth/OidcAuth/OidcAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { formatUnknownError } from 'utils/formatUnknownError';
import { removeEmptyStringFields } from 'utils/removeEmptyStringFields';
import { SsoGroupSettings } from '../SsoGroupSettings';
import type { IRole } from 'interfaces/role';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';

const initialState = {
enabled: false,
Expand All @@ -45,6 +46,7 @@ type State = typeof initialState & {
export const OidcAuth = () => {
const { setToastData, setToastApiError } = useToast();
const { uiConfig } = useUiConfig();
const { oidcConfiguredThroughEnv } = uiConfig;
const [data, setData] = useState<State>(initialState);
const { config } = useAuthSettings('oidc');
const { updateSettings, errors, loading } = useAuthSettingsApi('oidc');
Expand Down Expand Up @@ -107,6 +109,24 @@ export const OidcAuth = () => {
<>
<Grid container sx={{ mb: 3 }}>
<Grid item md={12}>
<ConditionallyRender
condition={Boolean(oidcConfiguredThroughEnv)}
show={
<Alert sx={{ mb: 2 }} severity='warning'>
OIDC setup is currently controlled via
environment variables. Please see the{' '}
<a
href='https://www.unleash-hosted.com/docs/enterprise-authentication'
target='_blank'
rel='noreferrer'
>
documentation
</a>{' '}
to learn how to set the correct environment
variables
</Alert>
}
/>
<Alert severity='info'>
Please read the{' '}
<a
Expand Down Expand Up @@ -140,6 +160,7 @@ export const OidcAuth = () => {
/>
}
label={data.enabled ? 'Enabled' : 'Disabled'}
disabled={oidcConfiguredThroughEnv}
/>
</Grid>
</Grid>
Expand All @@ -154,7 +175,7 @@ export const OidcAuth = () => {
label='Discover URL'
name='discoverUrl'
value={data.discoverUrl}
disabled={!data.enabled}
disabled={!data.enabled || oidcConfiguredThroughEnv}
style={{ width: '400px' }}
variant='outlined'
size='small'
Expand All @@ -172,7 +193,7 @@ export const OidcAuth = () => {
label='Client ID'
name='clientId'
value={data.clientId}
disabled={!data.enabled}
disabled={!data.enabled || oidcConfiguredThroughEnv}
style={{ width: '400px' }}
variant='outlined'
size='small'
Expand All @@ -193,7 +214,7 @@ export const OidcAuth = () => {
label='Client Secret'
name='secret'
value={data.secret}
disabled={!data.enabled}
disabled={!data.enabled || oidcConfiguredThroughEnv}
style={{ width: '400px' }}
variant='outlined'
size='small'
Expand All @@ -216,7 +237,10 @@ export const OidcAuth = () => {
<Switch
onChange={updateSingleSignOut}
value={data.enableSingleSignOut}
disabled={!data.enabled}
disabled={
!data.enabled ||
oidcConfiguredThroughEnv
}
name='enableSingleSignOut'
checked={data.enableSingleSignOut}
/>
Expand Down Expand Up @@ -247,7 +271,7 @@ export const OidcAuth = () => {
label='ACR Values'
name='acrValues'
value={data.acrValues}
disabled={!data.enabled}
disabled={!data.enabled || oidcConfiguredThroughEnv}
style={{ width: '400px' }}
variant='outlined'
size='small'
Expand All @@ -258,12 +282,14 @@ export const OidcAuth = () => {
ssoType='OIDC'
data={data}
setValue={setValue}
disabled={oidcConfiguredThroughEnv}
/>

<AutoCreateForm
data={data}
setValue={setValue}
onUpdateRole={onUpdateRole}
disabled={oidcConfiguredThroughEnv}
/>
<Grid container spacing={3} mb={2}>
<Grid item md={5}>
Expand Down Expand Up @@ -292,6 +318,7 @@ export const OidcAuth = () => {
e.target.value,
)
}
disabled={oidcConfiguredThroughEnv}
>
{/*consider these from API or constants. */}
<MenuItem value='RS256'>RS256</MenuItem>
Expand All @@ -308,7 +335,7 @@ export const OidcAuth = () => {
variant='contained'
color='primary'
type='submit'
disabled={loading}
disabled={loading || oidcConfiguredThroughEnv}
>
Save
</Button>{' '}
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/component/admin/auth/SsoGroupSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface SsoGroupSettingsProps {
addGroupsScope: boolean;
};
setValue: (name: string, value: string | boolean) => void;
disabled?: boolean;
}

export const SsoGroupSettings = ({
Expand All @@ -22,6 +23,7 @@ export const SsoGroupSettings = ({
addGroupsScope: false,
},
setValue,
disabled = false,
}: SsoGroupSettingsProps) => {
const updateGroupSyncing = () => {
setValue('enableGroupSyncing', !data.enableGroupSyncing);
Expand Down Expand Up @@ -53,7 +55,7 @@ export const SsoGroupSettings = ({
value={data.enableGroupSyncing}
name='enableGroupSyncing'
checked={data.enableGroupSyncing}
disabled={!data.enabled}
disabled={!data.enabled || disabled}
/>
}
label={data.enableGroupSyncing ? 'Enabled' : 'Disabled'}
Expand All @@ -74,7 +76,7 @@ export const SsoGroupSettings = ({
label='Group JSON Path'
name='groupJsonPath'
value={data.groupJsonPath}
disabled={!data.enableGroupSyncing}
disabled={!data.enableGroupSyncing || disabled}
style={{ width: '400px' }}
variant='outlined'
size='small'
Expand All @@ -99,7 +101,9 @@ export const SsoGroupSettings = ({
<Switch
onChange={updateAddGroupScope}
value={data.addGroupsScope}
disabled={!data.enableGroupSyncing}
disabled={
!data.enableGroupSyncing || disabled
}
name='addGroupsScope'
checked={data.addGroupsScope}
/>
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 @@ -30,6 +30,7 @@ export interface IUiConfig {
strategySegmentsLimit?: number;
frontendApiOrigins?: string[];
resourceLimits: ResourceLimitsSchema;
oidcConfiguredThroughEnv?: boolean;
}

export interface IProclamationToast {
Expand Down

0 comments on commit 7ed1d77

Please sign in to comment.