2024-03-18 13:58:05 +01:00
|
|
|
import type React from 'react';
|
|
|
|
import { useEffect, useState } from 'react';
|
2021-10-19 13:08:25 +02:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
FormControlLabel,
|
|
|
|
Grid,
|
|
|
|
Switch,
|
|
|
|
TextField,
|
2022-05-02 15:52:41 +02:00
|
|
|
} from '@mui/material';
|
|
|
|
import { Alert } from '@mui/material';
|
2022-02-08 11:44:41 +01:00
|
|
|
import { AutoCreateForm } from '../AutoCreateForm/AutoCreateForm';
|
2022-03-28 10:49:59 +02:00
|
|
|
import useToast from 'hooks/useToast';
|
|
|
|
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
|
|
|
import useAuthSettings from 'hooks/api/getters/useAuthSettings/useAuthSettings';
|
|
|
|
import useAuthSettingsApi from 'hooks/api/actions/useAuthSettingsApi/useAuthSettingsApi';
|
2022-03-25 12:34:20 +01:00
|
|
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
|
|
|
import { removeEmptyStringFields } from 'utils/removeEmptyStringFields';
|
2022-10-13 10:13:41 +02:00
|
|
|
import { SsoGroupSettings } from '../SsoGroupSettings';
|
2024-03-18 13:58:05 +01:00
|
|
|
import type { IRole } from 'interfaces/role';
|
2021-02-24 11:03:18 +01:00
|
|
|
|
|
|
|
const initialState = {
|
|
|
|
enabled: false,
|
|
|
|
autoCreate: false,
|
2022-10-13 10:13:41 +02:00
|
|
|
enableGroupSyncing: false,
|
2023-08-25 12:51:23 +02:00
|
|
|
addGroupsScope: false,
|
2021-02-24 11:03:18 +01:00
|
|
|
unleashHostname: location.hostname,
|
2022-02-08 11:44:41 +01:00
|
|
|
entityId: '',
|
|
|
|
signOnUrl: '',
|
|
|
|
certificate: '',
|
|
|
|
signOutUrl: '',
|
|
|
|
spCertificate: '',
|
2022-10-13 10:13:41 +02:00
|
|
|
groupJsonPath: '',
|
2021-02-24 11:03:18 +01:00
|
|
|
};
|
|
|
|
|
2024-01-16 17:08:46 +01:00
|
|
|
type State = typeof initialState & {
|
|
|
|
defaultRootRole?: string;
|
|
|
|
defaultRootRoleId?: number;
|
|
|
|
};
|
|
|
|
|
2022-02-08 11:44:41 +01:00
|
|
|
export const SamlAuth = () => {
|
|
|
|
const { setToastData, setToastApiError } = useToast();
|
|
|
|
const { uiConfig } = useUiConfig();
|
2024-01-16 17:08:46 +01:00
|
|
|
const [data, setData] = useState<State>(initialState);
|
2022-02-08 11:44:41 +01:00
|
|
|
const { config } = useAuthSettings('saml');
|
|
|
|
const { updateSettings, errors, loading } = useAuthSettingsApi('saml');
|
2021-02-24 11:03:18 +01:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (config.entityId) {
|
|
|
|
setData(config);
|
|
|
|
}
|
|
|
|
}, [config]);
|
|
|
|
|
2022-02-08 11:44:41 +01:00
|
|
|
const updateField = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
setValue(event.target.name, event.target.value);
|
2021-02-24 11:03:18 +01:00
|
|
|
};
|
|
|
|
|
2024-06-06 11:29:53 +02:00
|
|
|
const trimAndUpdateField = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
setValue(event.target.name, event.target.value.trim());
|
|
|
|
};
|
|
|
|
|
2021-02-24 11:03:18 +01:00
|
|
|
const updateEnabled = () => {
|
|
|
|
setData({ ...data, enabled: !data.enabled });
|
|
|
|
};
|
|
|
|
|
2024-01-15 14:13:29 +01:00
|
|
|
const setValue = (
|
|
|
|
name: string,
|
|
|
|
value: string | boolean | number | undefined,
|
|
|
|
) => {
|
2021-08-23 12:16:38 +02:00
|
|
|
setData({
|
|
|
|
...data,
|
2022-02-08 11:44:41 +01:00
|
|
|
[name]: value,
|
2021-08-23 12:16:38 +02:00
|
|
|
});
|
2021-10-19 13:08:25 +02:00
|
|
|
};
|
2021-02-24 11:03:18 +01:00
|
|
|
|
2024-01-16 17:08:46 +01:00
|
|
|
const onUpdateRole = (role: IRole | null) => {
|
|
|
|
setData({
|
|
|
|
...data,
|
|
|
|
defaultRootRole: undefined,
|
|
|
|
defaultRootRoleId: role?.id,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-02-08 11:44:41 +01:00
|
|
|
const onSubmit = async (event: React.SyntheticEvent) => {
|
|
|
|
event.preventDefault();
|
|
|
|
|
2021-02-24 11:03:18 +01:00
|
|
|
try {
|
2022-02-08 11:44:41 +01:00
|
|
|
await updateSettings(removeEmptyStringFields(data));
|
|
|
|
setToastData({
|
|
|
|
title: 'Settings stored',
|
|
|
|
type: 'success',
|
|
|
|
});
|
2022-02-25 10:55:39 +01:00
|
|
|
} catch (error: unknown) {
|
|
|
|
setToastApiError(formatUnknownError(error));
|
2021-02-24 11:03:18 +01:00
|
|
|
}
|
|
|
|
};
|
2022-02-08 11:44:41 +01:00
|
|
|
|
2021-02-24 11:03:18 +01:00
|
|
|
return (
|
2023-08-10 09:28:10 +02:00
|
|
|
<>
|
2023-05-23 16:56:34 +02:00
|
|
|
<Grid container sx={{ mb: 3 }}>
|
2021-03-30 15:14:02 +02:00
|
|
|
<Grid item md={12}>
|
2023-10-02 14:25:46 +02:00
|
|
|
<Alert severity='info'>
|
2021-02-24 11:03:18 +01:00
|
|
|
Please read the{' '}
|
2021-05-04 09:59:42 +02:00
|
|
|
<a
|
2023-10-02 14:25:46 +02:00
|
|
|
href='https://www.unleash-hosted.com/docs/enterprise-authentication'
|
|
|
|
target='_blank'
|
|
|
|
rel='noreferrer'
|
2021-05-04 09:59:42 +02:00
|
|
|
>
|
2021-02-24 11:03:18 +01:00
|
|
|
documentation
|
|
|
|
</a>{' '}
|
2021-05-04 09:59:42 +02:00
|
|
|
to learn how to integrate with specific SAML 2.0
|
|
|
|
providers (Okta, Keycloak, etc). <br />
|
|
|
|
Callback URL:{' '}
|
2022-02-08 11:44:41 +01:00
|
|
|
<code>{uiConfig.unleashUrl}/auth/saml/callback</code>
|
2021-04-16 11:31:47 +02:00
|
|
|
</Alert>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
2021-02-24 11:03:18 +01:00
|
|
|
</Grid>
|
|
|
|
<form onSubmit={onSubmit}>
|
2021-03-30 15:14:02 +02:00
|
|
|
<Grid container spacing={3}>
|
2022-05-02 15:52:41 +02:00
|
|
|
<Grid item md={5} mb={2}>
|
2021-02-24 11:03:18 +01:00
|
|
|
<strong>Enable</strong>
|
|
|
|
<p>Enable SAML 2.0 Authentication.</p>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
|
|
|
<Grid item md={6}>
|
2021-08-23 12:16:38 +02:00
|
|
|
<FormControlLabel
|
2021-10-19 13:08:25 +02:00
|
|
|
control={
|
|
|
|
<Switch
|
|
|
|
onChange={updateEnabled}
|
|
|
|
value={data.enabled}
|
2023-10-02 14:25:46 +02:00
|
|
|
name='enabled'
|
2021-10-19 13:08:25 +02:00
|
|
|
checked={data.enabled}
|
|
|
|
/>
|
|
|
|
}
|
2021-08-23 12:16:38 +02:00
|
|
|
label={data.enabled ? 'Enabled' : 'Disabled'}
|
|
|
|
/>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
2021-02-24 11:03:18 +01:00
|
|
|
</Grid>
|
2022-05-02 15:52:41 +02:00
|
|
|
<Grid container spacing={3} mb={2}>
|
2021-03-30 15:14:02 +02:00
|
|
|
<Grid item md={5}>
|
2021-02-24 11:03:18 +01:00
|
|
|
<strong>Entity ID</strong>
|
|
|
|
<p>(Required) The Entity Identity provider issuer.</p>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
|
|
|
<Grid item md={6}>
|
|
|
|
<TextField
|
2024-06-06 11:29:53 +02:00
|
|
|
onChange={trimAndUpdateField}
|
2023-10-02 14:25:46 +02:00
|
|
|
label='Entity ID'
|
|
|
|
name='entityId'
|
2022-02-08 11:44:41 +01:00
|
|
|
value={data.entityId}
|
2021-08-23 12:16:38 +02:00
|
|
|
disabled={!data.enabled}
|
2021-02-24 11:03:18 +01:00
|
|
|
style={{ width: '400px' }}
|
2023-10-02 14:25:46 +02:00
|
|
|
variant='outlined'
|
|
|
|
size='small'
|
2021-05-10 13:15:44 +02:00
|
|
|
required
|
2021-02-24 11:03:18 +01:00
|
|
|
/>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
2021-02-24 11:03:18 +01:00
|
|
|
</Grid>
|
2022-05-02 15:52:41 +02:00
|
|
|
<Grid container spacing={3} mb={2}>
|
2021-03-30 15:14:02 +02:00
|
|
|
<Grid item md={5}>
|
2021-02-24 11:03:18 +01:00
|
|
|
<strong>Single Sign-On URL</strong>
|
2021-05-04 09:59:42 +02:00
|
|
|
<p>
|
|
|
|
(Required) The url to redirect the user to for
|
|
|
|
signing in.
|
|
|
|
</p>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
|
|
|
<Grid item md={6}>
|
|
|
|
<TextField
|
2024-06-06 11:29:53 +02:00
|
|
|
onChange={trimAndUpdateField}
|
2023-10-02 14:25:46 +02:00
|
|
|
label='Single Sign-On URL'
|
|
|
|
name='signOnUrl'
|
2022-02-08 11:44:41 +01:00
|
|
|
value={data.signOnUrl}
|
2021-08-23 12:16:38 +02:00
|
|
|
disabled={!data.enabled}
|
2021-10-19 13:08:25 +02:00
|
|
|
style={{ width: '400px' }}
|
2023-10-02 14:25:46 +02:00
|
|
|
variant='outlined'
|
|
|
|
size='small'
|
2021-05-10 13:15:44 +02:00
|
|
|
required
|
2021-02-24 11:03:18 +01:00
|
|
|
/>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
2021-02-24 11:03:18 +01:00
|
|
|
</Grid>
|
2022-05-02 15:52:41 +02:00
|
|
|
<Grid container spacing={3} mb={4}>
|
2021-03-30 15:14:02 +02:00
|
|
|
<Grid item md={5}>
|
2021-02-24 11:03:18 +01:00
|
|
|
<strong>X.509 Certificate</strong>
|
2021-05-04 09:59:42 +02:00
|
|
|
<p>
|
|
|
|
(Required) The certificate used to sign the SAML 2.0
|
|
|
|
request.
|
|
|
|
</p>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
|
|
|
<Grid item md={7}>
|
|
|
|
<TextField
|
2021-02-24 11:03:18 +01:00
|
|
|
onChange={updateField}
|
2023-10-02 14:25:46 +02:00
|
|
|
label='X.509 Certificate'
|
|
|
|
name='certificate'
|
2022-02-08 11:44:41 +01:00
|
|
|
value={data.certificate}
|
2021-08-23 12:16:38 +02:00
|
|
|
disabled={!data.enabled}
|
2021-10-19 13:08:25 +02:00
|
|
|
style={{ width: '100%' }}
|
2021-07-20 22:56:57 +02:00
|
|
|
InputProps={{
|
|
|
|
style: {
|
|
|
|
fontSize: '0.6em',
|
|
|
|
fontFamily: 'monospace',
|
2021-10-19 13:08:25 +02:00
|
|
|
},
|
|
|
|
}}
|
2021-03-30 15:14:02 +02:00
|
|
|
multiline
|
2021-02-24 11:03:18 +01:00
|
|
|
rows={14}
|
2022-05-02 15:52:41 +02:00
|
|
|
maxRows={14}
|
2023-10-02 14:25:46 +02:00
|
|
|
variant='outlined'
|
|
|
|
size='small'
|
2021-05-10 13:15:44 +02:00
|
|
|
required
|
2021-02-24 11:03:18 +01:00
|
|
|
/>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
2021-02-24 11:03:18 +01:00
|
|
|
</Grid>
|
2021-07-20 22:56:57 +02:00
|
|
|
<h3>Optional Configuration</h3>
|
2022-05-02 15:52:41 +02:00
|
|
|
<Grid container spacing={3} mb={2}>
|
2021-07-20 22:56:57 +02:00
|
|
|
<Grid item md={5}>
|
|
|
|
<strong>Single Sign-out URL</strong>
|
|
|
|
<p>
|
2021-08-23 12:16:38 +02:00
|
|
|
(Optional) The url to redirect the user to for
|
2021-07-20 22:56:57 +02:00
|
|
|
signing out of the IDP.
|
|
|
|
</p>
|
|
|
|
</Grid>
|
|
|
|
<Grid item md={6}>
|
|
|
|
<TextField
|
2024-06-06 11:29:53 +02:00
|
|
|
onChange={trimAndUpdateField}
|
2023-10-02 14:25:46 +02:00
|
|
|
label='Single Sign-out URL'
|
|
|
|
name='signOutUrl'
|
2022-02-08 11:44:41 +01:00
|
|
|
value={data.signOutUrl}
|
2021-08-23 12:16:38 +02:00
|
|
|
disabled={!data.enabled}
|
2021-10-19 13:08:25 +02:00
|
|
|
style={{ width: '400px' }}
|
2023-10-02 14:25:46 +02:00
|
|
|
variant='outlined'
|
|
|
|
size='small'
|
2021-07-20 22:56:57 +02:00
|
|
|
/>
|
|
|
|
</Grid>
|
|
|
|
</Grid>
|
2022-05-02 15:52:41 +02:00
|
|
|
<Grid container spacing={3} mb={2}>
|
2021-07-20 22:56:57 +02:00
|
|
|
<Grid item md={5}>
|
|
|
|
<strong>Service Provider X.509 Certificate</strong>
|
|
|
|
<p>
|
2021-10-19 13:08:25 +02:00
|
|
|
(Optional) The private certificate used by the
|
|
|
|
Service Provider used to sign the SAML 2.0 request
|
|
|
|
towards the IDP. E.g. used to sign single logout
|
|
|
|
requests (SLO).
|
2021-07-20 22:56:57 +02:00
|
|
|
</p>
|
|
|
|
</Grid>
|
|
|
|
<Grid item md={7}>
|
|
|
|
<TextField
|
|
|
|
onChange={updateField}
|
2023-10-02 14:25:46 +02:00
|
|
|
label='X.509 Certificate'
|
|
|
|
name='spCertificate'
|
2022-02-08 11:44:41 +01:00
|
|
|
value={data.spCertificate}
|
2021-08-23 12:16:38 +02:00
|
|
|
disabled={!data.enabled}
|
2021-10-19 13:08:25 +02:00
|
|
|
style={{ width: '100%' }}
|
2021-07-20 22:56:57 +02:00
|
|
|
InputProps={{
|
|
|
|
style: {
|
|
|
|
fontSize: '0.6em',
|
|
|
|
fontFamily: 'monospace',
|
2021-10-19 13:08:25 +02:00
|
|
|
},
|
|
|
|
}}
|
2021-07-20 22:56:57 +02:00
|
|
|
multiline
|
|
|
|
rows={14}
|
2022-05-02 15:52:41 +02:00
|
|
|
maxRows={14}
|
2023-10-02 14:25:46 +02:00
|
|
|
variant='outlined'
|
|
|
|
size='small'
|
2021-07-20 22:56:57 +02:00
|
|
|
/>
|
|
|
|
</Grid>
|
|
|
|
</Grid>
|
2022-12-05 11:07:15 +01:00
|
|
|
|
|
|
|
<SsoGroupSettings
|
2023-10-02 14:25:46 +02:00
|
|
|
ssoType='SAML'
|
2022-12-05 11:07:15 +01:00
|
|
|
data={data}
|
|
|
|
setValue={setValue}
|
2022-10-13 10:13:41 +02:00
|
|
|
/>
|
|
|
|
|
2024-01-16 17:08:46 +01:00
|
|
|
<AutoCreateForm
|
|
|
|
data={data}
|
|
|
|
setValue={setValue}
|
|
|
|
onUpdateRole={onUpdateRole}
|
|
|
|
/>
|
2021-03-30 15:14:02 +02:00
|
|
|
<Grid container spacing={3}>
|
|
|
|
<Grid item md={5}>
|
2021-05-04 09:59:42 +02:00
|
|
|
<Button
|
2023-10-02 14:25:46 +02:00
|
|
|
variant='contained'
|
|
|
|
color='primary'
|
|
|
|
type='submit'
|
2022-02-08 11:44:41 +01:00
|
|
|
disabled={loading}
|
2021-05-04 09:59:42 +02:00
|
|
|
>
|
2021-02-24 11:03:18 +01:00
|
|
|
Save
|
|
|
|
</Button>{' '}
|
2022-02-08 11:44:41 +01:00
|
|
|
<p>
|
|
|
|
<small style={{ color: 'red' }}>
|
|
|
|
{errors?.message}
|
|
|
|
</small>
|
|
|
|
</p>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
2021-02-24 11:03:18 +01:00
|
|
|
</Grid>
|
|
|
|
</form>
|
2023-08-10 09:28:10 +02:00
|
|
|
</>
|
2021-02-24 11:03:18 +01:00
|
|
|
);
|
|
|
|
};
|