Browse Source

feat: Optimize OpenIddict management

pull/1588/head
colin 2 months ago
parent
commit
0b441864e5
  1. 18
      apps/vben5/packages/@abp/openiddict/src/api/useScopesApi.ts
  2. 30
      apps/vben5/packages/@abp/openiddict/src/components/applications/ApplicationModal.vue
  3. 56
      apps/vben5/packages/@abp/openiddict/src/components/applications/ApplicationSecretModal.vue
  4. 56
      apps/vben5/packages/@abp/openiddict/src/components/scopes/ScopeModal.vue
  5. 14
      apps/vben5/packages/@abp/openiddict/src/components/scopes/ScopeTable.vue
  6. 46
      apps/vben5/packages/@abp/openiddict/src/hooks/useScopeTransfer.ts
  7. 3
      aspnet-core/aspire/LINGYUN.Abp.MicroService.AuthServer.DbMigrator/appsettings.json
  8. 579
      aspnet-core/aspire/LINGYUN.Abp.MicroService.AuthServer.EntityFrameworkCore/DataSeeds/OpenIddictDataSeeder.cs
  9. 3
      aspnet-core/migrations/LY.MicroService.AuthServer.DbMigrator/appsettings.json
  10. 584
      aspnet-core/migrations/LY.MicroService.AuthServer.EntityFrameworkCore/DataSeeds/OpenIddictDataSeeder.cs
  11. 1
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Application.Contracts/LINGYUN/Abp/OpenIddict/Applications/OpenIddictApplicationDto.cs
  12. 1
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Application.Contracts/LINGYUN/Abp/OpenIddict/Localization/Resources/en.json
  13. 1
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Application.Contracts/LINGYUN/Abp/OpenIddict/Localization/Resources/zh-Hans.json
  14. 3
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Application.Contracts/LINGYUN/Abp/OpenIddict/Scopes/IOpenIddictScopeAppService.cs
  15. 1
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Application/LINGYUN/Abp/OpenIddict/Applications/OpenIddictApplicationExtensions.cs
  16. 11
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Application/LINGYUN/Abp/OpenIddict/Scopes/OpenIddictScopeAppService.cs
  17. 7
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.HttpApi/LINGYUN/Abp/OpenIddict/Scopes/OpenIddictScopeController.cs

18
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<OpenIddictScopeDto>
> {
return request<ListResultDto<OpenIddictScopeDto>>(
`/api/openiddict/scopes/assignable-scopes`,
{
method: 'GET',
},
);
}
return {
cancel,
createApi,
deleteApi,
getApi,
getAssignableScopesApi,
getPagedListApi,
updateApi,
};

30
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<OpenIddictApplicationDto>();
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"
/>
</FormItem>
<template v-if="formModel.clientType === 'confidential'">
<template
v-if="!formModel.id && formModel.clientType === 'confidential'"
>
<FormItem
v-if="!formModel.id"
:label="$t('AbpOpenIddict.DisplayName:ClientSecret')"
name="clientSecret"
>
@ -481,7 +479,7 @@ function onUriDelete(uri: string) {
<TabPane key="scope" :tab="$t('AbpOpenIddict.Scopes')">
<Transfer
v-model:target-keys="formModel.scopes"
:data-source="getSupportScopes"
:data-source="availableResources"
:list-style="{
width: '47%',
height: '338px',
@ -491,7 +489,7 @@ function onUriDelete(uri: string) {
$t('AbpOpenIddict.Assigned'),
$t('AbpOpenIddict.Available'),
]"
class="tree-transfer"
show-search
/>
</TabPane>
<!-- 授权 -->

56
apps/vben5/packages/@abp/openiddict/src/components/applications/ApplicationSecretModal.vue

@ -6,6 +6,7 @@ import { ref } from 'vue';
import { useVbenForm, useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { CodeEditor } from '@abp/components/codeeditor';
import { message } from 'ant-design-vue';
import { useApplicationsApi } from '../../api/useApplicationsApi';
@ -26,14 +27,52 @@ const [Form, formApi] = useVbenForm({
componentProps: {
class: 'w-full',
},
labelWidth: 130,
},
handleSubmit: onSubmit,
schema: [
{
component: 'Select',
componentProps: {
options: [
{
label: $t('AbpOpenIddict.DisplayName:ClientSecret'),
value: 'ClientSecret',
},
{
label: $t('AbpOpenIddict.DisplayName:JsonWebKeySet'),
value: 'JsonWebKeySet',
},
],
},
defaultValue: 'ClientSecret',
fieldName: 'keyType',
label: $t('AbpOpenIddict.DisplayName:ClientSecretType'),
rules: 'required',
},
{
component: 'InputPassword',
fieldName: 'clientSecret',
label: $t('AbpOpenIddict.DisplayName:ClientSecret'),
rules: 'required',
dependencies: {
triggerFields: ['keyType'],
show(values) {
return values.keyType === 'ClientSecret';
},
},
},
{
component: 'Input',
fieldName: 'jsonWebKeySet',
label: $t('AbpOpenIddict.DisplayName:JsonWebKeySet'),
rules: 'required',
dependencies: {
triggerFields: ['keyType'],
show(values) {
return values.keyType === 'JsonWebKeySet';
},
},
},
],
showDefaultActions: false,
@ -76,6 +115,7 @@ async function onSubmit(input: Record<string, any>) {
const dto = await updateApi(applicationModel.value!.id, {
...applicationModel.value!,
clientSecret: input.clientSecret,
jsonWebKeySet: input.jsonWebKeySet,
});
message.success($t('AbpUi.SavedSuccessfully'));
emits('change', dto);
@ -84,11 +124,25 @@ async function onSubmit(input: Record<string, any>) {
modalApi.setState({ submitting: false });
}
}
function onJsonWebKeySetChange(val?: string) {
formApi.setFieldValue('jsonWebKeySet', val);
}
</script>
<template>
<Modal>
<Form />
<Form>
<template #jsonWebKeySet="{ modelValue }">
<div class="w-full overflow-hidden rounded-md border border-gray-200">
<CodeEditor
:value="modelValue"
:options="{ lineNumbers: false }"
@change="onJsonWebKeySetChange"
/>
</div>
</template>
</Form>
</Modal>
</template>

56
apps/vben5/packages/@abp/openiddict/src/components/scopes/ScopeModal.vue

@ -1,21 +1,19 @@
<script setup lang="ts">
import type { OpenIdConfiguration } from '@abp/core';
import type { FormInstance } from 'ant-design-vue';
import type { TransferItem } from 'ant-design-vue/es/transfer';
import type { OpenIddictScopeDto } from '../../types/scopes';
import type { DisplayNameInfo } from '../display-names/types';
import type { PropertyInfo } from '../properties/types';
import { computed, defineEmits, defineOptions, ref, toValue } from 'vue';
import { defineEmits, defineOptions, ref, toValue } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { Form, Input, message, Tabs, Transfer } from 'ant-design-vue';
import { useOpenIdApi } from '../../api/useOpenIdApi';
import { useScopesApi } from '../../api/useScopesApi';
import { useScopeTransfer } from '../../hooks/useScopeTransfer';
import DisplayNameTable from '../display-names/DisplayNameTable.vue';
import PropertyTable from '../properties/PropertyTable.vue';
@ -30,32 +28,16 @@ const FormItem = Form.Item;
const TabPane = Tabs.TabPane;
type TabKeys =
| 'authorize'
| 'basic'
| 'description'
| 'dispalyName'
| 'props'
| 'resource';
'authorize' | 'basic' | 'description' | 'displayName' | 'props' | 'resource';
const defaultModel = {} as OpenIddictScopeDto;
const form = ref<FormInstance>();
const formModel = ref<OpenIddictScopeDto>({ ...defaultModel });
const openIdConfiguration = ref<OpenIdConfiguration>();
const activeTab = ref<TabKeys>('basic');
const getSupportClaims = computed((): TransferItem[] => {
const types = openIdConfiguration.value?.claims_supported ?? [];
return types.map((type) => {
return {
key: type,
title: type,
};
});
});
const { discoveryApi } = useOpenIdApi();
const { cancel, createApi, getApi, updateApi } = useScopesApi();
const { availableResources, initAssignableScopes } = useScopeTransfer();
const [Modal, modalApi] = useVbenModal({
class: 'w-1/2',
draggable: true,
@ -71,16 +53,15 @@ const [Modal, modalApi] = useVbenModal({
const api = formModel.value.id
? updateApi(formModel.value.id, toValue(formModel))
: createApi(toValue(formModel));
modalApi.setState({ submitting: true });
api
.then((res) => {
message.success($t('AbpUi.SavedSuccessfully'));
emits('change', res);
modalApi.close();
})
.finally(() => {
modalApi.setState({ submitting: false });
});
try {
modalApi.lock();
const res = await api;
message.success($t('AbpUi.SavedSuccessfully'));
emits('change', res);
modalApi.close();
} finally {
modalApi.unlock();
}
},
onOpenChange: async (isOpen: boolean) => {
if (isOpen) {
@ -91,7 +72,7 @@ const [Modal, modalApi] = useVbenModal({
});
try {
modalApi.setState({ loading: true });
await onDiscovery();
await initAssignableScopes();
const { id } = modalApi.getData<OpenIddictScopeDto>();
id && (await onGet(id));
} finally {
@ -108,9 +89,6 @@ async function onGet(id: string) {
title: `${$t('AbpOpenIddict.Scopes')} - ${dto.name}`,
});
}
async function onDiscovery() {
openIdConfiguration.value = await discoveryApi();
}
function onDescriptionChange(displayName: DisplayNameInfo) {
formModel.value.descriptions ??= {};
formModel.value.descriptions[displayName.culture] = displayName.displayName;
@ -157,7 +135,7 @@ function onPropDelete(prop: PropertyInfo) {
</FormItem>
</TabPane>
<!-- 显示名称 -->
<TabPane key="dispalyName" :tab="$t('AbpOpenIddict.DisplayNames')">
<TabPane key="displayName" :tab="$t('AbpOpenIddict.DisplayNames')">
<FormItem
:label="$t('AbpOpenIddict.DisplayName:DefaultDisplayName')"
name="displayName"
@ -188,7 +166,7 @@ function onPropDelete(prop: PropertyInfo) {
<TabPane key="resource" :tab="$t('AbpOpenIddict.Resources')">
<Transfer
v-model:target-keys="formModel.resources"
:data-source="getSupportClaims"
:data-source="availableResources"
:list-style="{
width: '47%',
height: '338px',
@ -198,7 +176,7 @@ function onPropDelete(prop: PropertyInfo) {
$t('AbpOpenIddict.Assigned'),
$t('AbpOpenIddict.Available'),
]"
class="tree-transfer"
show-search
/>
</TabPane>
<!-- 属性 -->

14
apps/vben5/packages/@abp/openiddict/src/components/scopes/ScopeTable.vue

@ -34,8 +34,6 @@ defineOptions({
const MenuItem = Menu.Item;
const AuditLogIcon = createIconifyIcon('fluent-mdl2:compliance-audit');
const CheckIcon = createIconifyIcon('ant-design:check-outlined');
const CloseIcon = createIconifyIcon('ant-design:close-outlined');
const { isEnabled } = useFeatures();
const { hasAccessByCodes } = useAccess();
@ -195,18 +193,6 @@ const onMenuClick = (row: OpenIddictScopeDto, info: MenuInfo) => {
{{ $t('AbpOpenIddict.Scopes:AddNew') }}
</Button>
</template>
<template #required="{ row }">
<div class="flex flex-row justify-center">
<CheckIcon v-if="row.required" class="text-green-500" />
<CloseIcon v-else class="text-red-500" />
</div>
</template>
<template #static="{ row }">
<div class="flex flex-row justify-center">
<CheckIcon v-if="row.isStatic" class="text-green-500" />
<CloseIcon v-else class="text-red-500" />
</div>
</template>
<template #action="{ row }">
<div class="flex flex-row">
<Button

46
apps/vben5/packages/@abp/openiddict/src/hooks/useScopeTransfer.ts

@ -0,0 +1,46 @@
import type { TransferItem } from 'ant-design-vue/es/transfer';
import { ref } from 'vue';
import { useAbpStore } from '@abp/core';
import { useScopesApi } from '../api/useScopesApi';
export function useScopeTransfer() {
const availableResources = ref<TransferItem[]>([]);
const abpStore = useAbpStore();
const { getAssignableScopesApi } = useScopesApi();
async function initAssignableScopes() {
const currentCulture =
abpStore.application?.localization.currentCulture.cultureName;
const { items } = await getAssignableScopesApi();
availableResources.value = items.map((resource) => {
let displayName = resource.displayName;
let description = resource.description;
if (resource.displayNames && currentCulture) {
const locales = Object.keys(resource.displayNames);
const locale = locales.find((x) => x.includes(currentCulture));
if (locale) {
displayName = resource.displayNames[locale];
}
}
if (resource.descriptions && currentCulture) {
const locales = Object.keys(resource.descriptions);
const locale = locales.find((x) => x.includes(currentCulture));
if (locale) {
description = resource.descriptions[locale];
}
}
return {
key: resource.name,
title: displayName,
description,
};
});
}
return {
initAssignableScopes,
availableResources,
};
}

3
aspnet-core/aspire/LINGYUN.Abp.MicroService.AuthServer.DbMigrator/appsettings.json

@ -26,7 +26,8 @@
"http://localhost:30040",
"http://localhost:30045",
"http://localhost:30050",
"http://localhost:30060"
"http://localhost:30060",
"http://localhost:30070"
]
}
}

579
aspnet-core/aspire/LINGYUN.Abp.MicroService.AuthServer.EntityFrameworkCore/DataSeeds/OpenIddictDataSeeder.cs

@ -5,6 +5,7 @@ using OpenIddict.Abstractions;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Data;
@ -39,14 +40,14 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
{
return;
}
var scope = "lingyun-abp-application";
var applicationScope = "lingyun-abp-application";
Logger.LogInformation("Seeding the default scope...");
await CreateDefaultScopeAsync();
await CreateApiScopeAsync(scope);
await CreateApiScopesAsync(applicationScope);
Logger.LogInformation("Seeding the default applications...");
await CreateApplicationAsync(scope);
await CreateApplicationAsync(applicationScope);
Logger.LogInformation("Seeding default applications completed.");
}
@ -54,152 +55,88 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
private async Task CreateDefaultScopeAsync()
{
// OpenId Connect
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.OpenId,
DisplayName = "OpenId Connect",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "身份认证",
[CultureInfo.GetCultureInfo("en")] = "OpenId Connect"
},
Description = "OpenId Connect协议进行身份验证",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序使用您的身份信息进行登录",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to authenticate you using OpenID Connect"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.OpenId,
"OpenId Connect",
"身份认证",
"OpenId Connect",
"OpenId Connect协议进行身份验证",
"允许应用程序使用您的身份信息进行登录",
"Allow the application to authenticate you using OpenID Connect");
// Profile
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.Profile,
DisplayName = "个人资料",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "个人资料",
[CultureInfo.GetCultureInfo("en")] = "Profile"
},
Description = "访问您的基本个人资料信息",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序访问您的姓名、头像等基本信息",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to access your basic profile information like name and picture"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.Profile,
"个人资料",
"个人资料",
"Profile",
"访问您的基本个人资料信息",
"允许应用程序访问您的姓名、头像等基本信息",
"Allow the application to access your basic profile information like name and picture");
// Email
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.Email,
DisplayName = "电子邮件",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "电子邮件",
[CultureInfo.GetCultureInfo("en")] = "Email"
},
Description = "访问您的电子邮件地址",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序访问您的电子邮件地址",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to access your email address"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.Email,
"电子邮件",
"电子邮件",
"Email",
"访问您的电子邮件地址",
"允许应用程序访问您的电子邮件地址",
"Allow the application to access your email address");
// Phone
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.Phone,
DisplayName = "电话号码",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "电话号码",
[CultureInfo.GetCultureInfo("en")] = "Phone"
},
Description = "访问您的电话号码",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序访问您的电话号码",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to access your phone number"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.Phone,
"电话号码",
"电话号码",
"Phone",
"访问您的电话号码",
"允许应用程序访问您的电话号码",
"Allow the application to access your phone number");
// Address
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.Address,
DisplayName = "地址信息",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "地址信息",
[CultureInfo.GetCultureInfo("en")] = "Address"
},
Description = "访问您的地址信息",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序访问您的地址信息",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to access your address information"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.Address,
"地址信息",
"地址信息",
"Address",
"访问您的地址信息",
"允许应用程序访问您的地址信息",
"Allow the application to access your address information");
// Roles
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.Roles,
DisplayName = "角色信息",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "角色信息",
[CultureInfo.GetCultureInfo("en")] = "Roles"
},
Description = "访问您的角色信息",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序访问您的角色和权限信息",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to access your roles and permissions"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.Roles,
"角色信息",
"角色信息",
"Roles",
"访问您的角色信息",
"允许应用程序访问您的角色和权限信息",
"Allow the application to access your roles and permissions");
// OfflineAccess
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.OfflineAccess,
DisplayName = "离线访问",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "离线访问",
[CultureInfo.GetCultureInfo("en")] = "Offline Access"
},
Description = "在您未登录时访问您的信息",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序在您未登录时访问您的信息",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to access your information while you are offline"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.OfflineAccess,
"离线访问",
"离线访问",
"Offline access",
"在您未登录时访问您的信息",
"允许应用程序在您未登录时访问您的信息",
"Allow the application to access your information while you are offline");
}
private async Task CreateApiScopeAsync(string scope)
private async Task CreateApiScopesAsync(string scope)
{
// 前端汇总授权范围
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = scope,
DisplayName = "微服务访问授权",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "微服务访问授权",
[CultureInfo.GetCultureInfo("en")] = "Single Applications"
},
Description = "适用于微服务体系的接口授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序使用各微服务模块的接口",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to use the interfaces of each microservice module"
},
Resources =
{
await CreateServiceScopeAsync(
scope,
"微服务访问授权",
"微服务访问授权",
"MicroService applications access",
"适用于微服务体系的接口授权",
"允许应用程序使用各微服务模块的接口",
"Allow the application to use the interfaces of each microservice module",
[
"api-gateway",
"auth-server",
"admin-service",
@ -211,240 +148,128 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
"task-service",
"webhook-service",
"wechat-service",
"workflow-service",
}
});
"workflow-service"
]);
// ApiGateway Swagger
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "api-gateway",
DisplayName = "Api Gateway",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "应用程序接口网关",
[CultureInfo.GetCultureInfo("en")] = "Api Gateway"
},
Description = "适用于应用程序接口网关Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于应用程序接口网关Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to application Programming interface gateway Swagger authorization"
},
Resources =
{
"api-gateway",
}
});
await CreateServiceScopeAsync(
"api-gateway",
"Api Gateway",
"应用程序接口网关",
"Api Gateway",
"适用于应用程序接口网关Swagger授权",
"适用于应用程序接口网关Swagger授权",
"Applicable to application Programming interface gateway Swagger authorization",
["api-gateway"]);
// Admin Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "admin-service",
DisplayName = "Admin Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "后台管理服务",
[CultureInfo.GetCultureInfo("en")] = "Admin Service"
},
Description = "适用于后台管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于后台管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the back-end management service Swagger authorization"
},
Resources =
{
"admin-service",
}
});
await CreateServiceScopeAsync(
"admin-service",
"Admin Service",
"后台管理服务",
"Admin Service",
"适用于后台管理服务Swagger授权",
"适用于后台管理服务Swagger授权",
"Applicable to the back-end management service Swagger authorization",
["admin-service"]);
// Auth Server
await CreateServiceScopeAsync(
"auth-server",
"Auth Server",
"身份认证服务器",
"Auth Server",
"适用于身份认证服务器Swagger授权",
"适用于身份认证服务器Swagger授权",
"Applicable to the auth server Swagger authorization",
["auth-server"]);
// Identity Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "identity-service",
DisplayName = "Identity Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "身份认证服务",
[CultureInfo.GetCultureInfo("en")] = "Identity Service"
},
Description = "适用于身份认证服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于身份认证服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the identity service Swagger authorization"
},
Resources =
{
"identity-service",
}
});
await CreateServiceScopeAsync(
"identity-service",
"Identity Service",
"身份认证服务",
"Identity Service",
"适用于身份认证服务Swagger授权",
"适用于身份认证服务Swagger授权",
"Applicable to the identity service Swagger authorization",
["identity-service"]);
// Localization Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "localization-service",
DisplayName = "Localization Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "本地化管理服务",
[CultureInfo.GetCultureInfo("en")] = "Localization Service"
},
Description = "适用于本地化管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于本地化管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Localization service Swagger authorization"
},
Resources =
{
"localization-service",
}
});
await CreateServiceScopeAsync(
"localization-service",
"Localization Service",
"本地化管理服务",
"Localization Service",
"适用于本地化管理服务Swagger授权",
"适用于本地化管理服务Swagger授权",
"Applicable to the Localization service Swagger authorization",
["localization-service"]);
// Message Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "message-service",
DisplayName = "Message Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "消息管理服务",
[CultureInfo.GetCultureInfo("en")] = "Message Service"
},
Description = "适用于消息管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于消息管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Message service Swagger authorization"
},
Resources =
{
"message-service",
}
});
await CreateServiceScopeAsync(
"message-service",
"Message Service",
"消息管理服务",
"Message Service",
"适用于消息管理服务Swagger授权",
"适用于消息管理服务Swagger授权",
"Applicable to the Message service Swagger authorization",
["message-service"]);
// Platform Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "platform-service",
DisplayName = "Platform Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "平台管理服务",
[CultureInfo.GetCultureInfo("en")] = "Platform Service"
},
Description = "适用于平台管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于平台管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Platform service Swagger authorization"
},
Resources =
{
"platform-service",
}
});
await CreateServiceScopeAsync(
"platform-service",
"Platform Service",
"平台管理服务",
"Platform Service",
"适用于平台管理服务Swagger授权",
"适用于平台管理服务Swagger授权",
"Applicable to the Platform service Swagger authorization",
["platform-service"]);
// Task Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "task-service",
DisplayName = "Task Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "任务管理服务",
[CultureInfo.GetCultureInfo("en")] = "Task Service"
},
Description = "适用于任务管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于任务管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Task service Swagger authorization"
},
Resources =
{
"task-service",
}
});
await CreateServiceScopeAsync(
"task-service",
"Task Service",
"任务管理服务",
"Task Service",
"适用于任务管理服务Swagger授权",
"适用于任务管理服务Swagger授权",
"Applicable to the Task service Swagger authorization",
["task-service"]);
// Webhook Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "webhook-service",
DisplayName = "Webhook Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "Webhook管理服务",
[CultureInfo.GetCultureInfo("en")] = "Webhook Service"
},
Description = "适用于Webhook管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于Webhook管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Webhook service Swagger authorization"
},
Resources =
{
"webhook-service",
}
});
await CreateServiceScopeAsync(
"webhook-service",
"Webhook Service",
"Webhook管理服务",
"Webhook Service",
"适用于Webhook管理服务Swagger授权",
"适用于Webhook管理服务Swagger授权",
"Applicable to the Webhook service Swagger authorization",
["webhook-service"]);
// Wechat Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "wechat-service",
DisplayName = "Wechat Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "微信管理服务",
[CultureInfo.GetCultureInfo("en")] = "Wechat Service"
},
Description = "适用于微信管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于微信管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Wechat service Swagger authorization"
},
Resources =
{
"wechat-service",
}
});
await CreateServiceScopeAsync(
"wechat-service",
"Wechat Service",
"微信管理服务",
"Wechat Service",
"适用于微信管理服务Swagger授权",
"适用于微信管理服务Swagger授权",
"Applicable to the Wechat service Swagger authorization",
["wechat-service"]);
// Workflow Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "workflow-service",
DisplayName = "Workflow Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "工作流管理服务",
[CultureInfo.GetCultureInfo("en")] = "Workflow Service"
},
Description = "适用于工作流管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于工作流管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Workflow service Swagger authorization"
},
Resources =
{
"workflow-service",
}
});
await CreateServiceScopeAsync(
"workflow-service",
"Workflow Service",
"工作流管理服务",
"Workflow Service",
"适用于工作流管理服务Swagger授权",
"适用于工作流管理服务Swagger授权",
"Applicable to the Workflow service Swagger authorization",
["workflow-service"]);
// AI Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "ai-service",
DisplayName = "Artificial Intelligence Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "AI管理服务",
[CultureInfo.GetCultureInfo("en")] = "Artificial Intelligence Service"
},
Description = "适用于AI管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于AI管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Artificial Intelligence service Swagger authorization"
},
Resources =
{
"ai-service",
}
});
await CreateServiceScopeAsync(
"ai-service",
"Artificial Intelligence Service",
"AI管理服务",
"Artificial Intelligence Service",
"适用于AI管理服务Swagger授权",
"适用于AI管理服务Swagger授权",
"Applicable to the Artificial Intelligence service Swagger authorization",
["ai-service"]);
}
private async Task CreateApplicationAsync(string scope)
@ -476,7 +301,6 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
"Abp Vue Admin Client",
configurationSection["VueAdmin:ClientSecret"] ?? "1q2w3e*",
[OpenIddictConstants.GrantTypes.AuthorizationCode,
OpenIddictConstants.GrantTypes.Implicit,
OpenIddictConstants.GrantTypes.Password,
OpenIddictConstants.GrantTypes.RefreshToken,
// TODO: 引用项目?
@ -506,14 +330,14 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
Logger.LogInformation("Seeding application {internalServiceClientId}...", internalServiceClientId);
await CreateOrUpdateApplicationAsync(
OpenIddictConstants.ApplicationTypes.Native,
OpenIddictConstants.ApplicationTypes.Web,
internalServiceClientId,
OpenIddictConstants.ClientTypes.Confidential,
OpenIddictConstants.ConsentTypes.Explicit,
OpenIddictConstants.ConsentTypes.Implicit,
"Abp Internal Service Client",
configurationSection["InternalService:ClientSecret"] ?? "1q2w3e*",
[OpenIddictConstants.GrantTypes.ClientCredentials],
[OpenIddictConstants.ResponseTypes.Token, scope]);
[scope]);
}
var oauthClientId = configurationSection["VueOAuthClient:ClientId"];
@ -544,7 +368,6 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
null,
[OpenIddictConstants.GrantTypes.AuthorizationCode,
OpenIddictConstants.GrantTypes.RefreshToken,
// TODO: 引用项目?
"link_user",
"impersonation"],
[OpenIddictConstants.Scopes.OpenId,
@ -577,4 +400,38 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
await PermissionDataSeeder.SeedAsync(ClientPermissionValueProvider.ProviderName, oauthClientId, oauthClientPermissions);
}
}
private async Task CreateServiceScopeAsync(
string name,
string displayNameDefault,
string displayNameZh,
string displayNameEn,
string descriptionDefault,
string descriptionZh,
string descriptionEn,
List<string>? resources = null)
{
var descriptor = new OpenIddictScopeDescriptor
{
Name = name,
DisplayName = displayNameDefault,
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = displayNameZh,
[CultureInfo.GetCultureInfo("en")] = displayNameEn
},
Description = descriptionDefault,
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = descriptionZh,
[CultureInfo.GetCultureInfo("en")] = descriptionEn
},
};
if (resources is { Count: > 0 })
{
descriptor.Resources.AddIfNotContains(resources);
}
await CreateScopesAsync(descriptor);
}
}

3
aspnet-core/migrations/LY.MicroService.AuthServer.DbMigrator/appsettings.json

@ -26,7 +26,8 @@
"http://localhost:30040",
"http://localhost:30045",
"http://localhost:30050",
"http://localhost:30060"
"http://localhost:30060",
"http://localhost:30070"
]
}
}

584
aspnet-core/migrations/LY.MicroService.AuthServer.EntityFrameworkCore/DataSeeds/OpenIddictDataSeeder.cs

@ -40,14 +40,14 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
{
return;
}
var scope = "lingyun-abp-application";
var applicationScope = "lingyun-abp-application";
Logger.LogInformation("Seeding the default scope...");
await CreateDefaultScopeAsync();
await CreateApiScopeAsync(scope);
await CreateApiScopesAsync(applicationScope);
Logger.LogInformation("Seeding the default applications...");
await CreateApplicationAsync(scope);
await CreateApplicationAsync(applicationScope);
Logger.LogInformation("Seeding default applications completed.");
}
@ -55,152 +55,88 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
private async Task CreateDefaultScopeAsync()
{
// OpenId Connect
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.OpenId,
DisplayName = "OpenId Connect",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "身份认证",
[CultureInfo.GetCultureInfo("en")] = "OpenId Connect"
},
Description = "OpenId Connect协议进行身份验证",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序使用您的身份信息进行登录",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to authenticate you using OpenID Connect"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.OpenId,
"OpenId Connect",
"身份认证",
"OpenId Connect",
"OpenId Connect协议进行身份验证",
"允许应用程序使用您的身份信息进行登录",
"Allow the application to authenticate you using OpenID Connect");
// Profile
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.Profile,
DisplayName = "个人资料",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "个人资料",
[CultureInfo.GetCultureInfo("en")] = "Profile"
},
Description = "访问您的基本个人资料信息",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序访问您的姓名、头像等基本信息",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to access your basic profile information like name and picture"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.Profile,
"个人资料",
"个人资料",
"Profile",
"访问您的基本个人资料信息",
"允许应用程序访问您的姓名、头像等基本信息",
"Allow the application to access your basic profile information like name and picture");
// Email
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.Email,
DisplayName = "电子邮件",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "电子邮件",
[CultureInfo.GetCultureInfo("en")] = "Email"
},
Description = "访问您的电子邮件地址",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序访问您的电子邮件地址",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to access your email address"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.Email,
"电子邮件",
"电子邮件",
"Email",
"访问您的电子邮件地址",
"允许应用程序访问您的电子邮件地址",
"Allow the application to access your email address");
// Phone
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.Phone,
DisplayName = "电话号码",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "电话号码",
[CultureInfo.GetCultureInfo("en")] = "Phone"
},
Description = "访问您的电话号码",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序访问您的电话号码",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to access your phone number"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.Phone,
"电话号码",
"电话号码",
"Phone",
"访问您的电话号码",
"允许应用程序访问您的电话号码",
"Allow the application to access your phone number");
// Address
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.Address,
DisplayName = "地址信息",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "地址信息",
[CultureInfo.GetCultureInfo("en")] = "Address"
},
Description = "访问您的地址信息",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序访问您的地址信息",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to access your address information"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.Address,
"地址信息",
"地址信息",
"Address",
"访问您的地址信息",
"允许应用程序访问您的地址信息",
"Allow the application to access your address information");
// Roles
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.Roles,
DisplayName = "角色信息",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "角色信息",
[CultureInfo.GetCultureInfo("en")] = "Roles"
},
Description = "访问您的角色信息",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序访问您的角色和权限信息",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to access your roles and permissions"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.Roles,
"角色信息",
"角色信息",
"Roles",
"访问您的角色信息",
"允许应用程序访问您的角色和权限信息",
"Allow the application to access your roles and permissions");
// OfflineAccess
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = OpenIddictConstants.Scopes.OfflineAccess,
DisplayName = "离线访问",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "离线访问",
[CultureInfo.GetCultureInfo("en")] = "Offline Access"
},
Description = "在您未登录时访问您的信息",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序在您未登录时访问您的信息",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to access your information while you are offline"
}
});
await CreateServiceScopeAsync(
OpenIddictConstants.Scopes.OfflineAccess,
"离线访问",
"离线访问",
"Offline access",
"在您未登录时访问您的信息",
"允许应用程序在您未登录时访问您的信息",
"Allow the application to access your information while you are offline");
}
private async Task CreateApiScopeAsync(string scope)
private async Task CreateApiScopesAsync(string scope)
{
// 前端汇总授权范围
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = scope,
DisplayName = "微服务访问授权",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "微服务访问授权",
[CultureInfo.GetCultureInfo("en")] = "Single Applications"
},
Description = "适用于微服务体系的接口授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "允许应用程序使用各微服务模块的接口",
[CultureInfo.GetCultureInfo("en")] = "Allow the application to use the interfaces of each microservice module"
},
Resources =
{
await CreateServiceScopeAsync(
scope,
"微服务访问授权",
"微服务访问授权",
"MicroService applications access",
"适用于微服务体系的接口授权",
"允许应用程序使用各微服务模块的接口",
"Allow the application to use the interfaces of each microservice module",
[
"api-gateway",
"auth-server",
"admin-service",
@ -212,240 +148,128 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
"task-service",
"webhook-service",
"wechat-service",
"workflow-service",
}
});
"workflow-service"
]);
// ApiGateway Swagger
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "api-gateway",
DisplayName = "Api Gateway",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "应用程序接口网关",
[CultureInfo.GetCultureInfo("en")] = "Api Gateway"
},
Description = "适用于应用程序接口网关Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于应用程序接口网关Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to application Programming interface gateway Swagger authorization"
},
Resources =
{
"api-gateway",
}
});
await CreateServiceScopeAsync(
"api-gateway",
"Api Gateway",
"应用程序接口网关",
"Api Gateway",
"适用于应用程序接口网关Swagger授权",
"适用于应用程序接口网关Swagger授权",
"Applicable to application Programming interface gateway Swagger authorization",
["api-gateway"]);
// Admin Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "admin-service",
DisplayName = "Admin Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "后台管理服务",
[CultureInfo.GetCultureInfo("en")] = "Admin Service"
},
Description = "适用于后台管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于后台管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the back-end management service Swagger authorization"
},
Resources =
{
"admin-service",
}
});
await CreateServiceScopeAsync(
"admin-service",
"Admin Service",
"后台管理服务",
"Admin Service",
"适用于后台管理服务Swagger授权",
"适用于后台管理服务Swagger授权",
"Applicable to the back-end management service Swagger authorization",
["admin-service"]);
// Auth Server
await CreateServiceScopeAsync(
"auth-server",
"Auth Server",
"身份认证服务器",
"Auth Server",
"适用于身份认证服务器Swagger授权",
"适用于身份认证服务器Swagger授权",
"Applicable to the auth server Swagger authorization",
["auth-server"]);
// Identity Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "identity-service",
DisplayName = "Identity Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "身份认证服务",
[CultureInfo.GetCultureInfo("en")] = "Identity Service"
},
Description = "适用于身份认证服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于身份认证服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the identity service Swagger authorization"
},
Resources =
{
"identity-service",
}
});
await CreateServiceScopeAsync(
"identity-service",
"Identity Service",
"身份认证服务",
"Identity Service",
"适用于身份认证服务Swagger授权",
"适用于身份认证服务Swagger授权",
"Applicable to the identity service Swagger authorization",
["identity-service"]);
// Localization Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "localization-service",
DisplayName = "Localization Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "本地化管理服务",
[CultureInfo.GetCultureInfo("en")] = "Localization Service"
},
Description = "适用于本地化管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于本地化管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Localization service Swagger authorization"
},
Resources =
{
"localization-service",
}
});
await CreateServiceScopeAsync(
"localization-service",
"Localization Service",
"本地化管理服务",
"Localization Service",
"适用于本地化管理服务Swagger授权",
"适用于本地化管理服务Swagger授权",
"Applicable to the Localization service Swagger authorization",
["localization-service"]);
// Message Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "message-service",
DisplayName = "Message Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "消息管理服务",
[CultureInfo.GetCultureInfo("en")] = "Message Service"
},
Description = "适用于消息管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于消息管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Message service Swagger authorization"
},
Resources =
{
"message-service",
}
});
await CreateServiceScopeAsync(
"message-service",
"Message Service",
"消息管理服务",
"Message Service",
"适用于消息管理服务Swagger授权",
"适用于消息管理服务Swagger授权",
"Applicable to the Message service Swagger authorization",
["message-service"]);
// Platform Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "platform-service",
DisplayName = "Platform Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "平台管理服务",
[CultureInfo.GetCultureInfo("en")] = "Platform Service"
},
Description = "适用于平台管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于平台管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Platform service Swagger authorization"
},
Resources =
{
"platform-service",
}
});
await CreateServiceScopeAsync(
"platform-service",
"Platform Service",
"平台管理服务",
"Platform Service",
"适用于平台管理服务Swagger授权",
"适用于平台管理服务Swagger授权",
"Applicable to the Platform service Swagger authorization",
["platform-service"]);
// Task Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "task-service",
DisplayName = "Task Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "任务管理服务",
[CultureInfo.GetCultureInfo("en")] = "Task Service"
},
Description = "适用于任务管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于任务管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Task service Swagger authorization"
},
Resources =
{
"task-service",
}
});
await CreateServiceScopeAsync(
"task-service",
"Task Service",
"任务管理服务",
"Task Service",
"适用于任务管理服务Swagger授权",
"适用于任务管理服务Swagger授权",
"Applicable to the Task service Swagger authorization",
["task-service"]);
// Webhook Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "webhook-service",
DisplayName = "Webhook Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "Webhook管理服务",
[CultureInfo.GetCultureInfo("en")] = "Webhook Service"
},
Description = "适用于Webhook管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于Webhook管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Webhook service Swagger authorization"
},
Resources =
{
"webhook-service",
}
});
await CreateServiceScopeAsync(
"webhook-service",
"Webhook Service",
"Webhook管理服务",
"Webhook Service",
"适用于Webhook管理服务Swagger授权",
"适用于Webhook管理服务Swagger授权",
"Applicable to the Webhook service Swagger authorization",
["webhook-service"]);
// Wechat Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "wechat-service",
DisplayName = "Wechat Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "微信管理服务",
[CultureInfo.GetCultureInfo("en")] = "Wechat Service"
},
Description = "适用于微信管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于微信管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Wechat service Swagger authorization"
},
Resources =
{
"wechat-service",
}
});
await CreateServiceScopeAsync(
"wechat-service",
"Wechat Service",
"微信管理服务",
"Wechat Service",
"适用于微信管理服务Swagger授权",
"适用于微信管理服务Swagger授权",
"Applicable to the Wechat service Swagger authorization",
["wechat-service"]);
// Workflow Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "workflow-service",
DisplayName = "Workflow Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "工作流管理服务",
[CultureInfo.GetCultureInfo("en")] = "Workflow Service"
},
Description = "适用于工作流管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于工作流管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Workflow service Swagger authorization"
},
Resources =
{
"workflow-service",
}
});
await CreateServiceScopeAsync(
"workflow-service",
"Workflow Service",
"工作流管理服务",
"Workflow Service",
"适用于工作流管理服务Swagger授权",
"适用于工作流管理服务Swagger授权",
"Applicable to the Workflow service Swagger authorization",
["workflow-service"]);
// AI Service
await CreateScopesAsync(new OpenIddictScopeDescriptor
{
Name = "ai-service",
DisplayName = "Artificial Intelligence Service",
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "AI管理服务",
[CultureInfo.GetCultureInfo("en")] = "Artificial Intelligence Service"
},
Description = "适用于AI管理服务Swagger授权",
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = "适用于AI管理服务Swagger授权",
[CultureInfo.GetCultureInfo("en")] = "Applicable to the Artificial Intelligence service Swagger authorization"
},
Resources =
{
"ai-service",
}
});
await CreateServiceScopeAsync(
"ai-service",
"Artificial Intelligence Service",
"AI管理服务",
"Artificial Intelligence Service",
"适用于AI管理服务Swagger授权",
"适用于AI管理服务Swagger授权",
"Applicable to the Artificial Intelligence service Swagger authorization",
["ai-service"]);
}
private async Task CreateApplicationAsync(string scope)
@ -477,11 +301,11 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
"Abp Vue Admin Client",
configurationSection["VueAdmin:ClientSecret"] ?? "1q2w3e*",
[OpenIddictConstants.GrantTypes.AuthorizationCode,
OpenIddictConstants.GrantTypes.Implicit,
OpenIddictConstants.GrantTypes.Password,
OpenIddictConstants.GrantTypes.RefreshToken,
// TODO: 引用项目?
"link_user"],
"link_user",
"impersonation"],
[OpenIddictConstants.Scopes.OpenId,
OpenIddictConstants.Scopes.Email,
OpenIddictConstants.Scopes.Roles,
@ -506,14 +330,14 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
Logger.LogInformation("Seeding application {internalServiceClientId}...", internalServiceClientId);
await CreateOrUpdateApplicationAsync(
OpenIddictConstants.ApplicationTypes.Native,
OpenIddictConstants.ApplicationTypes.Web,
internalServiceClientId,
OpenIddictConstants.ClientTypes.Confidential,
OpenIddictConstants.ConsentTypes.Explicit,
OpenIddictConstants.ConsentTypes.Implicit,
"Abp Internal Service Client",
configurationSection["InternalService:ClientSecret"] ?? "1q2w3e*",
[OpenIddictConstants.GrantTypes.ClientCredentials],
[OpenIddictConstants.ResponseTypes.Token, scope]);
[scope]);
}
var oauthClientId = configurationSection["VueOAuthClient:ClientId"];
@ -544,8 +368,8 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
null,
[OpenIddictConstants.GrantTypes.AuthorizationCode,
OpenIddictConstants.GrantTypes.RefreshToken,
// TODO: 引用项目?
"link_user"],
"link_user",
"impersonation"],
[OpenIddictConstants.Scopes.OpenId,
OpenIddictConstants.Scopes.Email,
OpenIddictConstants.Scopes.Roles,
@ -576,4 +400,38 @@ public class OpenIddictDataSeeder : OpenIddictDataSeedContributorBase, ITransien
await PermissionDataSeeder.SeedAsync(ClientPermissionValueProvider.ProviderName, oauthClientId, oauthClientPermissions);
}
}
private async Task CreateServiceScopeAsync(
string name,
string displayNameDefault,
string displayNameZh,
string displayNameEn,
string descriptionDefault,
string descriptionZh,
string descriptionEn,
List<string>? resources = null)
{
var descriptor = new OpenIddictScopeDescriptor
{
Name = name,
DisplayName = displayNameDefault,
DisplayNames =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = displayNameZh,
[CultureInfo.GetCultureInfo("en")] = displayNameEn
},
Description = descriptionDefault,
Descriptions =
{
[CultureInfo.GetCultureInfo("zh-Hans")] = descriptionZh,
[CultureInfo.GetCultureInfo("en")] = descriptionEn
},
};
if (resources is { Count: > 0 })
{
descriptor.Resources.AddIfNotContains(resources);
}
await CreateScopesAsync(descriptor);
}
}

1
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Application.Contracts/LINGYUN/Abp/OpenIddict/Applications/OpenIddictApplicationDto.cs

@ -25,7 +25,6 @@ public class OpenIddictApplicationDto : ExtensibleAuditedEntityDto<Guid>, IHasCo
public string? ApplicationType { get; set; }
public string? ClientUri { get; set; }
public string? LogoUri { get; set; }
public string? JsonWebKeySet { get; set; }
public string ConcurrencyStamp { get; set; } = default!;
public string? FrontChannelLogoutUri { get; set; }
}

1
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Application.Contracts/LINGYUN/Abp/OpenIddict/Localization/Resources/en.json

@ -14,6 +14,7 @@
"OpenIddict:001001": "The application client id {ClientId} already exists!",
"OpenIddict:002001": "The scope name {Name} already exists!",
"DisplayName:ClientId": "Client Id",
"DisplayName:ClientSecretType": "Secret Type",
"DisplayName:ClientSecret": "Client Secret",
"Description:ClientSecret": "Please copy the key information before saving. You can only reset the key after the data is submitted.",
"DisplayName:JsonWebKeySet": "Json web key set",

1
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Application.Contracts/LINGYUN/Abp/OpenIddict/Localization/Resources/zh-Hans.json

@ -14,6 +14,7 @@
"OpenIddict:001001": "应用标识 {ClientId} 已经存在!",
"OpenIddict:002001": "范围名称 {Name} 已经存在!",
"DisplayName:ClientId": "客户端标识",
"DisplayName:ClientSecretType": "密钥类型",
"DisplayName:ClientSecret": "客户端密钥",
"Description:ClientSecret": "请在保存之前复制密钥信息,数据提交后将只能重置密钥.",
"DisplayName:JsonWebKeySet": "JSON Web 密钥集",

3
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Application.Contracts/LINGYUN/Abp/OpenIddict/Scopes/IOpenIddictScopeAppService.cs

@ -1,4 +1,6 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace LINGYUN.Abp.OpenIddict.Scopes;
@ -11,4 +13,5 @@ public interface IOpenIddictScopeAppService :
OpenIddictScopeCreateDto,
OpenIddictScopeUpdateDto>
{
Task<ListResultDto<OpenIddictScopeDto>> GetAssignableScopesAsync();
}

1
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Application/LINGYUN/Abp/OpenIddict/Applications/OpenIddictApplicationExtensions.cs

@ -105,7 +105,6 @@ internal static class OpenIddictApplicationExtensions
ApplicationType = entity.ApplicationType,
ClientUri = entity.ClientUri,
LogoUri = entity.LogoUri,
JsonWebKeySet = entity.JsonWebKeySet,
ConcurrencyStamp = entity.ConcurrencyStamp,
FrontChannelLogoutUri = entity.FrontChannelLogoutUri,
};

11
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.Application/LINGYUN/Abp/OpenIddict/Scopes/OpenIddictScopeAppService.cs

@ -65,13 +65,20 @@ public class OpenIddictScopeAppService : OpenIddictApplicationServiceBase, IOpen
return scope.ToDto(JsonSerializer)!;
}
public async virtual Task<ListResultDto<OpenIddictScopeDto>> GetAssignableScopesAsync()
{
var entities = await _scoppeRepository.GetListAsync();
return new ListResultDto<OpenIddictScopeDto>(entities.Select(entity => entity.ToDto(JsonSerializer)!).ToList());
}
public async virtual Task<PagedResultDto<OpenIddictScopeDto>> GetListAsync(OpenIddictScopeGetListInput input)
{
var totalCount = await _scoppeRepository.GetCountAsync(input.Filter);
var entites = await _scoppeRepository.GetListAsync(input.Sorting, input.SkipCount, input.MaxResultCount, input.Filter);
var entities = await _scoppeRepository.GetListAsync(input.Sorting, input.SkipCount, input.MaxResultCount, input.Filter);
return new PagedResultDto<OpenIddictScopeDto>(totalCount,
entites.Select(entity => entity.ToDto(JsonSerializer)!).ToList());
entities.Select(entity => entity.ToDto(JsonSerializer)!).ToList());
}
[Authorize(AbpOpenIddictPermissions.Scopes.Update)]

7
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.HttpApi/LINGYUN/Abp/OpenIddict/Scopes/OpenIddictScopeController.cs

@ -44,6 +44,13 @@ public class OpenIddictScopeController : OpenIddictControllerBase, IOpenIddictSc
return Service.GetAsync(id);
}
[HttpGet]
[Route("assignable-scopes")]
public virtual Task<ListResultDto<OpenIddictScopeDto>> GetAssignableScopesAsync()
{
return Service.GetAssignableScopesAsync();
}
[HttpGet]
public virtual Task<PagedResultDto<OpenIddictScopeDto>> GetListAsync(OpenIddictScopeGetListInput input)
{

Loading…
Cancel
Save