import React, { useContext, useEffect, useState } from 'react'; import { Button, FormControlLabel, Grid, Switch, TextField, } from '@material-ui/core'; import { Alert } from '@material-ui/lab'; import PageContent from '../../../common/PageContent/PageContent'; import AccessContext from '../../../../contexts/AccessContext'; import { ADMIN } from '../../../providers/AccessProvider/permissions'; import { AutoCreateForm } from '../AutoCreateForm/AutoCreateForm'; import useUiConfig from '../../../../hooks/api/getters/useUiConfig/useUiConfig'; import useAuthSettingsApi from '../../../../hooks/api/actions/useAuthSettingsApi/useAuthSettingsApi'; import useAuthSettings from '../../../../hooks/api/getters/useAuthSettings/useAuthSettings'; import useToast from '../../../../hooks/useToast'; import { formatUnknownError } from '../../../../utils/format-unknown-error'; import { removeEmptyStringFields } from '../../../../utils/remove-empty-string-fields'; const initialState = { enabled: false, enableSingleSignOut: false, autoCreate: false, unleashHostname: location.hostname, clientId: '', discoverUrl: '', secret: '', acrValues: '', }; export const OidcAuth = () => { const { setToastData, setToastApiError } = useToast(); const { uiConfig } = useUiConfig(); const [data, setData] = useState(initialState); const { hasAccess } = useContext(AccessContext); const { config } = useAuthSettings('oidc'); const { updateSettings, errors, loading } = useAuthSettingsApi('oidc'); useEffect(() => { if (config.discoverUrl) { setData(config); } }, [config]); if (!hasAccess(ADMIN)) { return ( You need to be a root admin to access this section. ); } const updateField = (event: React.ChangeEvent) => { setValue(event.target.name, event.target.value); }; const updateEnabled = () => { setData({ ...data, enabled: !data.enabled }); }; const updateSingleSignOut = () => { setData({ ...data, enableSingleSignOut: !data.enableSingleSignOut }); }; const setValue = (name: string, value: string | boolean) => { setData({ ...data, [name]: value, }); }; const onSubmit = async (event: React.SyntheticEvent) => { event.preventDefault(); try { await updateSettings(removeEmptyStringFields(data)); setToastData({ title: 'Settings stored', type: 'success', }); } catch (err) { setToastApiError(formatUnknownError(err)); } }; return ( Please read the{' '} documentation {' '} to learn how to integrate with specific Open Id Connect providers (Okta, Keycloak, Google, etc).
Callback URL:{' '} {uiConfig.unleashUrl}/auth/oidc/callback
Enable

Enable Open Id Connect Authentication.

} label={data.enabled ? 'Enabled' : 'Disabled'} />
Discover URL

(Required) Issuer discover metadata URL

Client ID

(Required) Client ID of your OpenID application

Client secret

(Required) Client secret of your OpenID application.{' '}

Optional Configuration

Enable Single Sign-Out

If you enable Single Sign-Out Unleash will redirect the user to the IDP as part of the Sign-out process.

} label={ data.enableSingleSignOut ? 'Enabled' : 'Disabled' } />
ACR Values

Requested Authentication Context Class Reference values. If multiple values are specified they should be "space" separated. Will be sent as "acr_values" as part of the authentication request. Unleash will validate the acr value in the id token claims against the list of acr values.

{' '}

{errors?.message}

); };