2021-02-24 11:03:18 +01:00
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-03-30 15:14:02 +02:00
|
|
|
import { Button, Grid, Switch, TextField, Typography } from '@material-ui/core';
|
|
|
|
import PageContent from '../../../component/common/PageContent/PageContent';
|
2021-02-24 11:03:18 +01:00
|
|
|
|
|
|
|
const initialState = {
|
|
|
|
enabled: false,
|
|
|
|
autoCreate: false,
|
|
|
|
unleashHostname: location.hostname,
|
|
|
|
};
|
|
|
|
|
|
|
|
function SamlAuth({ config, getSamlConfig, updateSamlConfig, hasPermission }) {
|
|
|
|
const [data, setData] = useState(initialState);
|
|
|
|
const [info, setInfo] = useState();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
getSamlConfig();
|
2021-04-07 09:04:48 +02:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2021-02-24 11:03:18 +01:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (config.entityId) {
|
|
|
|
setData(config);
|
|
|
|
}
|
2021-04-07 09:04:48 +02:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2021-02-24 11:03:18 +01:00
|
|
|
}, [config]);
|
|
|
|
|
|
|
|
if (!hasPermission('ADMIN')) {
|
|
|
|
return <span>You need admin privileges to access this section.</span>;
|
|
|
|
}
|
|
|
|
|
|
|
|
const updateField = e => {
|
|
|
|
setData({
|
|
|
|
...data,
|
|
|
|
[e.target.name]: e.target.value,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const updateEnabled = () => {
|
|
|
|
setData({ ...data, enabled: !data.enabled });
|
|
|
|
};
|
|
|
|
|
|
|
|
const updateAutoCreate = () => {
|
|
|
|
setData({ ...data, autoCreate: !data.autoCreate });
|
|
|
|
};
|
|
|
|
|
|
|
|
const onSubmit = async e => {
|
|
|
|
e.preventDefault();
|
|
|
|
setInfo('...saving');
|
|
|
|
try {
|
|
|
|
await updateSamlConfig(data);
|
|
|
|
setInfo('Settings stored');
|
|
|
|
setTimeout(() => setInfo(''), 2000);
|
|
|
|
} catch (e) {
|
|
|
|
setInfo(e.message);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return (
|
2021-03-30 15:14:02 +02:00
|
|
|
<PageContent>
|
|
|
|
<Grid container style={{ marginBottom: '1rem' }}>
|
|
|
|
<Grid item md={12}>
|
|
|
|
<Typography variant="subtitle1">
|
2021-02-24 11:03:18 +01:00
|
|
|
Please read the{' '}
|
2021-04-07 09:04:48 +02:00
|
|
|
<a href="https://www.unleash-hosted.com/docs/enterprise-authentication" target="_blank" rel="noreferrer">
|
2021-02-24 11:03:18 +01:00
|
|
|
documentation
|
|
|
|
</a>{' '}
|
2021-03-30 15:14:02 +02:00
|
|
|
to learn how to integrate with specific SAML 2.0 providers (Okta, Keycloak, etc). <br />
|
2021-02-24 11:03:18 +01:00
|
|
|
Callback URL: <code>https://[unleash.hostname.com]/auth/saml/callback</code>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Typography>
|
|
|
|
</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}>
|
|
|
|
<Grid item md={5}>
|
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}>
|
|
|
|
<Switch onChange={updateEnabled} value={data.enabled} name="enabled" checked={data.enabled}>
|
2021-02-24 11:03:18 +01:00
|
|
|
{data.enabled ? 'Enabled' : 'Disabled'}
|
|
|
|
</Switch>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
2021-02-24 11:03:18 +01:00
|
|
|
</Grid>
|
2021-03-30 15:14:02 +02:00
|
|
|
<Grid container spacing={3}>
|
|
|
|
<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
|
2021-02-24 11:03:18 +01:00
|
|
|
onChange={updateField}
|
|
|
|
label="Entity ID"
|
|
|
|
name="entityId"
|
2021-03-30 15:14:02 +02:00
|
|
|
value={data.entityId || ''}
|
2021-02-24 11:03:18 +01:00
|
|
|
style={{ width: '400px' }}
|
2021-03-30 15:14:02 +02:00
|
|
|
variant="outlined"
|
|
|
|
size="small"
|
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-03-30 15:14:02 +02:00
|
|
|
<Grid container spacing={3}>
|
|
|
|
<Grid item md={5}>
|
2021-02-24 11:03:18 +01:00
|
|
|
<strong>Single Sign-On URL</strong>
|
|
|
|
<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
|
2021-02-24 11:03:18 +01:00
|
|
|
onChange={updateField}
|
|
|
|
label="Single Sign-On URL"
|
|
|
|
name="signOnUrl"
|
2021-03-30 15:14:02 +02:00
|
|
|
value={data.signOnUrl || ''}
|
2021-02-24 11:03:18 +01:00
|
|
|
style={{ width: '400px' }}
|
2021-03-30 15:14:02 +02:00
|
|
|
variant="outlined"
|
|
|
|
size="small"
|
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-03-30 15:14:02 +02:00
|
|
|
<Grid container spacing={3}>
|
|
|
|
<Grid item md={5}>
|
2021-02-24 11:03:18 +01:00
|
|
|
<strong>X.509 Certificate</strong>
|
|
|
|
<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}
|
|
|
|
label="X.509 Certificate"
|
|
|
|
name="certificate"
|
2021-03-30 15:14:02 +02:00
|
|
|
value={data.certificate || ''}
|
|
|
|
style={{
|
|
|
|
width: '100%',
|
|
|
|
fontSize: '0.7em',
|
|
|
|
fontFamily: 'monospace',
|
|
|
|
}}
|
|
|
|
multiline
|
2021-02-24 11:03:18 +01:00
|
|
|
rows={14}
|
2021-03-30 15:14:02 +02:00
|
|
|
rowsMax={14}
|
|
|
|
variant="outlined"
|
|
|
|
size="small"
|
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-03-30 15:14:02 +02:00
|
|
|
<Grid container spacing={3}>
|
|
|
|
<Grid item md={5}>
|
2021-02-24 11:03:18 +01:00
|
|
|
<strong>Auto-create users</strong>
|
|
|
|
<p>Enable automatic creation of new users when signing in with Saml.</p>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
|
|
|
<Grid item md={6} style={{ padding: '20px' }}>
|
2021-02-24 11:03:18 +01:00
|
|
|
<Switch onChange={updateAutoCreate} name="enabled" checked={data.autoCreate}>
|
|
|
|
Auto-create users
|
|
|
|
</Switch>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
2021-02-24 11:03:18 +01:00
|
|
|
</Grid>
|
2021-03-30 15:14:02 +02:00
|
|
|
<Grid container spacing={3}>
|
|
|
|
<Grid item md={5}>
|
2021-02-24 11:03:18 +01:00
|
|
|
<strong>Email domains</strong>
|
|
|
|
<p>(Optional) Comma separated list of email domains that should be allowed to sign in.</p>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
|
|
|
<Grid item md={6}>
|
|
|
|
<TextField
|
2021-02-24 11:03:18 +01:00
|
|
|
onChange={updateField}
|
|
|
|
label="Email domains"
|
|
|
|
name="emailDomains"
|
2021-03-30 15:14:02 +02:00
|
|
|
value={data.emailDomains || ''}
|
2021-02-24 11:03:18 +01:00
|
|
|
placeholder="@company.com, @anotherCompany.com"
|
|
|
|
style={{ width: '400px' }}
|
|
|
|
rows={2}
|
2021-03-30 15:14:02 +02:00
|
|
|
variant="outlined"
|
|
|
|
size="small"
|
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-03-30 15:14:02 +02:00
|
|
|
<Grid container spacing={3}>
|
|
|
|
<Grid item md={5}>
|
|
|
|
<Button variant="contained" color="primary" type="submit">
|
2021-02-24 11:03:18 +01:00
|
|
|
Save
|
|
|
|
</Button>{' '}
|
|
|
|
<small>{info}</small>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Grid>
|
2021-02-24 11:03:18 +01:00
|
|
|
</Grid>
|
|
|
|
</form>
|
2021-03-30 15:14:02 +02:00
|
|
|
</PageContent>
|
2021-02-24 11:03:18 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
SamlAuth.propTypes = {
|
|
|
|
config: PropTypes.object,
|
|
|
|
getSamlConfig: PropTypes.func.isRequired,
|
|
|
|
updateSamlConfig: PropTypes.func.isRequired,
|
|
|
|
hasPermission: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SamlAuth;
|