From 0b441864e52bee601b8deb48b0bb0a3cac66ea4a Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 24 Sep 2026 10:01:31 +0800 Subject: [PATCH] feat: Optimize OpenIddict management --- .../@abp/openiddict/src/api/useScopesApi.ts | 18 +- .../applications/ApplicationModal.vue | 30 +- .../applications/ApplicationSecretModal.vue | 56 +- .../src/components/scopes/ScopeModal.vue | 56 +- .../src/components/scopes/ScopeTable.vue | 14 - .../openiddict/src/hooks/useScopeTransfer.ts | 46 ++ .../appsettings.json | 3 +- .../DataSeeds/OpenIddictDataSeeder.cs | 579 +++++++---------- .../appsettings.json | 3 +- .../DataSeeds/OpenIddictDataSeeder.cs | 584 +++++++----------- .../Applications/OpenIddictApplicationDto.cs | 1 - .../OpenIddict/Localization/Resources/en.json | 1 + .../Localization/Resources/zh-Hans.json | 1 + .../Scopes/IOpenIddictScopeAppService.cs | 3 + .../OpenIddictApplicationExtensions.cs | 1 - .../Scopes/OpenIddictScopeAppService.cs | 11 +- .../Scopes/OpenIddictScopeController.cs | 7 + 17 files changed, 613 insertions(+), 801 deletions(-) create mode 100644 apps/vben5/packages/@abp/openiddict/src/hooks/useScopeTransfer.ts diff --git a/apps/vben5/packages/@abp/openiddict/src/api/useScopesApi.ts b/apps/vben5/packages/@abp/openiddict/src/api/useScopesApi.ts index 76430c07d..99a2e5d7b 100644 --- a/apps/vben5/packages/@abp/openiddict/src/api/useScopesApi.ts +++ b/apps/vben5/packages/@abp/openiddict/src/api/useScopesApi.ts @@ -1,4 +1,4 @@ -import type { PagedResultDto } from '@abp/core'; +import type { ListResultDto, PagedResultDto } from '@abp/core'; import type { OpenIddictScopeCreateDto, @@ -78,11 +78,27 @@ export function useScopesApi() { ); } + /** + * 查询可用范围列表 + * @returns 可用范围实体数据传输对象列表 + */ + function getAssignableScopesApi(): Promise< + ListResultDto + > { + return request>( + `/api/openiddict/scopes/assignable-scopes`, + { + method: 'GET', + }, + ); + } + return { cancel, createApi, deleteApi, getApi, + getAssignableScopesApi, getPagedListApi, updateApi, }; diff --git a/apps/vben5/packages/@abp/openiddict/src/components/applications/ApplicationModal.vue b/apps/vben5/packages/@abp/openiddict/src/components/applications/ApplicationModal.vue index 5aa604aeb..fd0e997c9 100644 --- a/apps/vben5/packages/@abp/openiddict/src/components/applications/ApplicationModal.vue +++ b/apps/vben5/packages/@abp/openiddict/src/components/applications/ApplicationModal.vue @@ -3,7 +3,6 @@ import type { OpenIdConfiguration } from '@abp/core'; import type { FormInstance } from 'ant-design-vue'; import type { MenuInfo } from 'ant-design-vue/es/menu/src/interface'; import type { DefaultOptionType } from 'ant-design-vue/es/select'; -import type { TransferItem } from 'ant-design-vue/es/transfer'; import type { Component } from 'vue'; @@ -43,6 +42,7 @@ import { import { useApplicationsApi } from '../../api/useApplicationsApi'; import { useOpenIdApi } from '../../api/useOpenIdApi'; +import { useScopeTransfer } from '../../hooks/useScopeTransfer'; import DisplayNameTable from '../display-names/DisplayNameTable.vue'; import PropertyTable from '../properties/PropertyTable.vue'; @@ -141,18 +141,10 @@ const getResponseTypes = computed(() => { }; }); }); -const getSupportScopes = computed((): TransferItem[] => { - const types = openIdConfiguration.value?.scopes_supported ?? []; - return types.map((type) => { - return { - key: type, - title: type, - }; - }); -}); const { discoveryApi } = useOpenIdApi(); const { cancel, createApi, getApi, updateApi } = useApplicationsApi(); +const { availableResources, initAssignableScopes } = useScopeTransfer(); const [Modal, modalApi] = useVbenModal({ class: 'w-1/2', draggable: true, @@ -190,7 +182,7 @@ const [Modal, modalApi] = useVbenModal({ }); try { modalApi.setState({ loading: true }); - await onDiscovery(); + await onInit(); const claimTypeDto = modalApi.getData(); if (claimTypeDto?.id) { const dto = await getApi(claimTypeDto.id); @@ -207,7 +199,10 @@ const [Modal, modalApi] = useVbenModal({ }, title: 'ClaimType', }); -async function onDiscovery() { +async function onInit() { + await Promise.all([onLoadConfiguration(), initAssignableScopes()]); +} +async function onLoadConfiguration() { openIdConfiguration.value = await discoveryApi(); } function onDisplayNameChange(displayName: DisplayNameInfo) { @@ -250,11 +245,13 @@ function onUriChange(uri: string) { case 'PostLogoutRedirectUris': { formModel.value.postLogoutRedirectUris ??= []; formModel.value.postLogoutRedirectUris.push(uri); + uriComponentState.uris = formModel.value.postLogoutRedirectUris; break; } case 'RedirectUris': { formModel.value.redirectUris ??= []; formModel.value.redirectUris.push(uri); + uriComponentState.uris = formModel.value.redirectUris; break; } } @@ -339,9 +336,10 @@ function onUriDelete(uri: string) { :options="clientTypes" /> -