feat: Support quick configuration of OIDC through Well-Known Discovery Endpoint

This commit is contained in:
OnEvent 2024-08-13 14:35:06 +08:00
parent f8144fe534
commit e66b73faf5
No known key found for this signature in database
GPG Key ID: 3CDB9068A32B4927

View File

@ -34,6 +34,7 @@ const SystemSetting = () => {
LarkClientId: '', LarkClientId: '',
LarkClientSecret: '', LarkClientSecret: '',
OidcEnabled: '', OidcEnabled: '',
OidcWellKnown: '',
OidcClientId: '', OidcClientId: '',
OidcClientSecret: '', OidcClientSecret: '',
OidcAuthorizationEndpoint: '', OidcAuthorizationEndpoint: '',
@ -150,8 +151,9 @@ const SystemSetting = () => {
name === 'MessagePusherToken' || name === 'MessagePusherToken' ||
name === 'LarkClientId' || name === 'LarkClientId' ||
name === 'LarkClientSecret' || name === 'LarkClientSecret' ||
name === 'OidcAppId' || name === 'OidcClientId' ||
name === 'OidcAppSecret' || name === 'OidcClientSecret' ||
name === 'OidcWellKnown' ||
name === 'OidcAuthorizationEndpoint' || name === 'OidcAuthorizationEndpoint' ||
name === 'OidcTokenEndpoint' || name === 'OidcTokenEndpoint' ||
name === 'OidcUserinfoEndpoint' name === 'OidcUserinfoEndpoint'
@ -239,14 +241,25 @@ const SystemSetting = () => {
}; };
const submitOidc = async () => { const submitOidc = async () => {
const OidcConfig = { if (inputs.OidcWellKnown !== '') {
OidcClientId: inputs.OidcClientId, if (!inputs.OidcWellKnown.startsWith('http://') && !inputs.OidcWellKnown.startsWith('https://')) {
OidcClientSecret: inputs.OidcClientSecret, showError('Well-Known URL 必须以 http:// 或 https:// 开头');
OidcAuthorizationEndpoint: inputs.OidcAuthorizationEndpoint, return;
OidcTokenEndpoint: inputs.OidcTokenEndpoint, }
OidcUserinfoEndpoint: inputs.OidcUserinfoEndpoint try {
}; const res = await API.get(inputs.OidcWellKnown);
console.log(OidcConfig); inputs.OidcAuthorizationEndpoint = res.data['authorization_endpoint'];
inputs.OidcTokenEndpoint = res.data['token_endpoint'];
inputs.OidcUserinfoEndpoint = res.data['userinfo_endpoint'];
showSuccess('获取 OIDC 配置成功!');
} catch (err) {
showError("获取 OIDC 配置失败,请检查网络状况和 Well-Known URL 是否正确");
}
}
if (originInputs['OidcWellKnown'] !== inputs.OidcWellKnown) {
await updateOption('OidcWellKnown', inputs.OidcWellKnown);
}
if (originInputs['OidcClientId'] !== inputs.OidcClientId) { if (originInputs['OidcClientId'] !== inputs.OidcClientId) {
await updateOption('OidcClientId', inputs.OidcClientId); await updateOption('OidcClientId', inputs.OidcClientId);
} }
@ -675,6 +688,9 @@ const SystemSetting = () => {
<Alert severity="info" sx={ { wordWrap: 'break-word' } }> <Alert severity="info" sx={ { wordWrap: 'break-word' } }>
主页链接填 <code>{ inputs.ServerAddress }</code> 主页链接填 <code>{ inputs.ServerAddress }</code>
重定向 URL <code>{ `${ inputs.ServerAddress }/oauth/oidc` }</code> 重定向 URL <code>{ `${ inputs.ServerAddress }/oauth/oidc` }</code>
</Alert> <br />
<Alert severity="info" sx={ { wordWrap: 'break-word' } }>
若你的 OIDC Provider 支持 Discovery Endpoint你可以仅填写 OIDC Well-Known URL系统会自动获取 OIDC 配置
</Alert> </Alert>
</Grid> </Grid>
<Grid xs={ 12 } md={ 6 }> <Grid xs={ 12 } md={ 6 }>
@ -705,6 +721,20 @@ const SystemSetting = () => {
/> />
</FormControl> </FormControl>
</Grid> </Grid>
<Grid xs={ 12 } md={ 6 }>
<FormControl fullWidth>
<InputLabel htmlFor="OidcWellKnown">Well-Known URL</InputLabel>
<OutlinedInput
id="OidcWellKnown"
name="OidcWellKnown"
value={ inputs.OidcWellKnown || '' }
onChange={ handleInputChange }
label="Well-Known URL"
placeholder="请输入 OIDC 的 Well-Known URL"
disabled={ loading }
/>
</FormControl>
</Grid>
<Grid xs={ 12 } md={ 6 }> <Grid xs={ 12 } md={ 6 }>
<FormControl fullWidth> <FormControl fullWidth>
<InputLabel htmlFor="OidcAuthorizationEndpoint">Authorization Endpoint</InputLabel> <InputLabel htmlFor="OidcAuthorizationEndpoint">Authorization Endpoint</InputLabel>
@ -741,7 +771,7 @@ const SystemSetting = () => {
name="OidcUserinfoEndpoint" name="OidcUserinfoEndpoint"
value={ inputs.OidcUserinfoEndpoint || '' } value={ inputs.OidcUserinfoEndpoint || '' }
onChange={ handleInputChange } onChange={ handleInputChange }
label="认证地址" label="Userinfo Endpoint"
placeholder="输入 OIDC 的 Userinfo Endpoint" placeholder="输入 OIDC 的 Userinfo Endpoint"
disabled={ loading } disabled={ loading }
/> />