1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-20 14:54:15 +01:00

(gui) auto discover scopes

This commit is contained in:
Sylvain 2022-04-20 10:28:14 +02:00
parent 007c97969d
commit 0f183e7af6
2 changed files with 13 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import { HtmlTranslate } from '../base/html-translate';
import { OpenIdConnectProvider } from '../../models/authentication-provider';
import SsoClient from '../../api/external/sso';
import { FieldPathValue } from 'react-hook-form/dist/types/path';
import { FormMultiSelect } from '../form/form-multi-select';
interface OpenidConnectFormProps<TFieldValues, TContext extends object> {
register: UseFormRegister<TFieldValues>,
@ -23,6 +24,7 @@ export const OpenidConnectForm = <TFieldValues extends FieldValues, TContext ext
// saves the state of the discovery endpoint
const [discoveryAvailable, setDiscoveryAvailable] = useState<boolean>(false);
const [scopesAvailable, setScopesAvailable] = useState<string[]>(null);
// when we have detected a discovery endpoint, we mark it as available
useEffect(() => {
@ -63,10 +65,12 @@ export const OpenidConnectForm = <TFieldValues extends FieldValues, TContext ext
* This callback is triggered when the user changes the issuer field.
*/
const checkForDiscoveryEndpoint = (e: React.ChangeEvent<HTMLInputElement>) => {
SsoClient.openIdConfiguration(e.target.value).then(() => {
SsoClient.openIdConfiguration(e.target.value).then((configuration) => {
setDiscoveryAvailable(true);
setScopesAvailable(configuration.scopes_supported);
}).catch(() => {
setDiscoveryAvailable(false);
setScopesAvailable(null);
});
};
@ -98,11 +102,16 @@ export const OpenidConnectForm = <TFieldValues extends FieldValues, TContext ext
]}
valueDefault={'basic'}
control={control} />
<FormInput id="providable_attributes.scope"
{!scopesAvailable && <FormInput id="providable_attributes.scope"
register={register}
label={t('app.admin.authentication.openid_connect_form.scope')}
placeholder="openid,profile,email"
tooltip={t('app.admin.authentication.openid_connect_form.scope_help')} />
tooltip={<HtmlTranslate trKey="app.admin.authentication.openid_connect_form.scope_help_html" />} />}
{scopesAvailable && <FormMultiSelect id="providable_attributes.scope"
label={t('app.admin.authentication.openid_connect_form.scope')}
tooltip={<HtmlTranslate trKey="app.admin.authentication.openid_connect_form.scope_help_html" />}
options={scopesAvailable.map((scope) => ({ value: scope, label: scope }))}
control={control} />}
<FormSelect id="providable_attributes.prompt"
label={t('app.admin.authentication.openid_connect_form.prompt')}
tooltip={<HtmlTranslate trKey="app.admin.authentication.openid_connect_form.prompt_help_html" />}

View File

@ -1109,7 +1109,7 @@ en:
client_auth_method_basic: "Basic"
client_auth_method_jwks: "JWKS"
scope: "Scope"
scope_help: "Which OpenID scopes to include (openid is always required)"
scope_help_html: "Which OpenID scopes to include (openid is always required). <br> If <b>Discovery</b> is enabled, the available scopes will be automatically proposed."
prompt: "Prompt"
prompt_help_html: "Which OpenID pages the user will be shown. <br> <b>None</b> - no authentication or consent user interface pages are shown. <br> <b>Login</b> - the authorization server prompt the user for reauthentication. <br> <b>Consent</b> - the authorization server prompt the user for consent before returning information to Fab-manager. <br> <b>Select account</b> - the authorization server prompt the user to select a user account."
prompt_none: "None"