From 495d51d6b6fc641794bddc98df101a046b3c230e Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 10 Jan 2026 15:41:38 +0800 Subject: [PATCH] feat(oauth): Rewrite the user authorize page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重写OpenIddict授权同意页,允许用户勾选授权范围 --- Directory.Packages.props | 732 +++++++++--------- .../app-antd/src/locales/langs/en-US/abp.json | 3 +- .../app-antd/src/locales/langs/zh-CN/abp.json | 3 +- .../apps/app-antd/src/router/routes/core.ts | 2 +- apps/vben5/apps/app-antd/src/store/auth.ts | 6 +- .../views/_core/fallback/login-callback.vue | 16 +- .../@abp/account/src/hooks/useOAuthError.ts | 12 +- .../src/components/scopes/ScopeModal.vue | 50 +- .../LINGYUN.MicroService.SingleProject.sln | 11 +- .../appsettings.Development.json | 3 +- .../ApiGatewayModule.cs | 10 +- .../Program.cs | 2 +- .../appsettings.Development.json | 6 +- .../yarp.json | 95 ++- .../AuthServerModule.Configure.cs | 16 +- .../appsettings.Development.json | 10 +- .../package.json | 6 +- .../appsettings.Development.json | 3 +- .../appsettings.Development.json | 3 +- .../appsettings.Development.json | 3 +- .../appsettings.Development.json | 3 +- .../appsettings.Development.json | 7 +- .../appsettings.Development.json | 6 +- .../appsettings.Development.json | 3 +- .../appsettings.Development.json | 4 +- .../AbpAccountWebOpenIddictModule.cs | 25 +- .../Controllers/AuthorizeController.cs | 338 ++++++++ .../LINGYUN.Abp.Account.Web.OpenIddict.csproj | 8 + .../Localization/Resources/en.json | 6 + .../Localization/Resources/zh-Hans.json | 6 + .../Authorize/AuthorizeViewModel.cs | 23 + .../Views/Authorize/Authorize.cshtml | 90 +++ .../Views/Authorize/Authorize.js | 29 + .../Views/_ViewImports.cshtml | 4 + .../AbpAccountWebModule.cs | 1 + .../Pages/Account/Login.cshtml | 7 +- ...rviceApplicationsSingleModule.Configure.cs | 2 +- .../appsettings.Development.json | 3 +- 38 files changed, 1045 insertions(+), 512 deletions(-) create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Controllers/AuthorizeController.cs create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Localization/Resources/en.json create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Localization/Resources/zh-Hans.json create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/ViewModels/Authorize/AuthorizeViewModel.cs create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Views/Authorize/Authorize.cshtml create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Views/Authorize/Authorize.js create mode 100644 aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Views/_ViewImports.cshtml diff --git a/Directory.Packages.props b/Directory.Packages.props index 92b49bd1d..60258d5f0 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,367 +1,367 @@ - - 10.0.0 - 2.15.2 - 3.3.5 - 10.0.2 - 10.0.2 - 10.0.0 - 10.0.0 - 10.0.0 - 13.1.0 - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + 10.0.0 + 2.15.2 + 3.3.5 + 10.0.2 + 10.0.2 + 10.0.0 + 10.0.0 + 10.0.0 + 13.1.0 + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json b/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json index 49dced4c6..84408903b 100644 --- a/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json +++ b/apps/vben5/apps/app-antd/src/locales/langs/en-US/abp.json @@ -18,7 +18,8 @@ "invalidUserNameOrPassword": "Invalid username or password!", "tokenHasExpired": "The token is no longer valid!", "requiresTwoFactor": "Identity verification is required. Please select a verification method!", - "shouldChangePassword": "Your password has expired. Please change it and login!" + "shouldChangePassword": "Your password has expired. Please change it and login!", + "accessDenied": "You have refused the necessary authorization for the application. Please log in again!" } }, "manage": { diff --git a/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json b/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json index 16bb7ec01..bdf07a393 100644 --- a/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json +++ b/apps/vben5/apps/app-antd/src/locales/langs/zh-CN/abp.json @@ -18,7 +18,8 @@ "invalidUserNameOrPassword": "用户名或密码错误!", "tokenHasExpired": "您的请求会话已过期,请重新登录!", "requiresTwoFactor": "需要验证身份,请选择一种验证方式!", - "shouldChangePassword": "您的密码已过期,请修改密码后登录!" + "shouldChangePassword": "您的密码已过期,请修改密码后登录!", + "accessDenied": "您拒绝了应用程序必须的授权, 请重新登录!" } }, "manage": { diff --git a/apps/vben5/apps/app-antd/src/router/routes/core.ts b/apps/vben5/apps/app-antd/src/router/routes/core.ts index 959ed35c1..032207207 100644 --- a/apps/vben5/apps/app-antd/src/router/routes/core.ts +++ b/apps/vben5/apps/app-antd/src/router/routes/core.ts @@ -28,7 +28,7 @@ const coreRoutes: RouteRecordRaw[] = [ hideInBreadcrumb: true, hideInMenu: true, hideInTab: true, - title: 'Processing login', + title: $t('page.auth.processingLogin'), }, name: 'OidcFallback', path: '/signin-callback', diff --git a/apps/vben5/apps/app-antd/src/store/auth.ts b/apps/vben5/apps/app-antd/src/store/auth.ts index 3b3452809..6c7240094 100644 --- a/apps/vben5/apps/app-antd/src/store/auth.ts +++ b/apps/vben5/apps/app-antd/src/store/auth.ts @@ -1,4 +1,4 @@ -import type { TokenResult } from '@abp/account'; +import type { OAuthError, TokenResult } from '@abp/account'; import type { Recordable, UserInfo } from '@vben/types'; @@ -45,7 +45,7 @@ export const useAuthStore = defineStore('auth', () => { await oAuthService.login(); } - async function oidcCallback() { + async function oidcCallback(onError?: (error: OAuthError) => void) { try { const user = await oAuthService.handleCallback(); return await _loginSuccess({ @@ -55,6 +55,8 @@ export const useAuthStore = defineStore('auth', () => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion expiresIn: user.expires_in!, }); + } catch (error: any) { + onError && onError(error as OAuthError); } finally { loginLoading.value = false; } diff --git a/apps/vben5/apps/app-antd/src/views/_core/fallback/login-callback.vue b/apps/vben5/apps/app-antd/src/views/_core/fallback/login-callback.vue index 9ec43d98e..5081589e1 100644 --- a/apps/vben5/apps/app-antd/src/views/_core/fallback/login-callback.vue +++ b/apps/vben5/apps/app-antd/src/views/_core/fallback/login-callback.vue @@ -1,12 +1,26 @@ diff --git a/apps/vben5/packages/@abp/account/src/hooks/useOAuthError.ts b/apps/vben5/packages/@abp/account/src/hooks/useOAuthError.ts index a1e821002..64fc93d0b 100644 --- a/apps/vben5/packages/@abp/account/src/hooks/useOAuthError.ts +++ b/apps/vben5/packages/@abp/account/src/hooks/useOAuthError.ts @@ -1,10 +1,6 @@ -import { $t } from '@vben/locales'; +import type { OAuthError } from '../types/token'; -interface OAuthError { - error: string; - error_description?: string; - error_uri?: string; -} +import { $t } from '@vben/locales'; export function useOAuthError() { function formatError(error: OAuthError) { @@ -22,6 +18,10 @@ export function useOAuthError() { case 'RequiresTwoFactor': { return $t('abp.oauth.errors.requiresTwoFactor'); } + // 用户拒绝授权 + case 'The authorization was denied by the end user.': { + return $t('abp.oauth.errors.accessDenied'); + } // Token已失效 case 'The token is no longer valid.': case 'The user is no longer allowed to sign in.': { diff --git a/apps/vben5/packages/@abp/openiddict/src/components/scopes/ScopeModal.vue b/apps/vben5/packages/@abp/openiddict/src/components/scopes/ScopeModal.vue index dc2892d42..ba4b1f08d 100644 --- a/apps/vben5/packages/@abp/openiddict/src/components/scopes/ScopeModal.vue +++ b/apps/vben5/packages/@abp/openiddict/src/components/scopes/ScopeModal.vue @@ -1,20 +1,17 @@