From c2d078ca8737e2da62a6023bce53f7db2be7e8b5 Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 5 Jun 2025 20:22:08 +0800 Subject: [PATCH] fix(openiddict): Fixed openiddict login model - Modify base class source --- .../Account/TwoFactorSupportedLoginModel.cs | 53 ++++++++----------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Pages/Account/TwoFactorSupportedLoginModel.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Pages/Account/TwoFactorSupportedLoginModel.cs index 376372223..41ae2c17e 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Pages/Account/TwoFactorSupportedLoginModel.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Pages/Account/TwoFactorSupportedLoginModel.cs @@ -1,64 +1,57 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; -using System.Collections.Generic; +using System; using System.Threading.Tasks; using Volo.Abp.Account.Web; -using Volo.Abp.Account.Web.Pages.Account; using Volo.Abp.DependencyInjection; using Volo.Abp.Identity; +using Volo.Abp.MultiTenancy; using Volo.Abp.OpenIddict; using IdentityOptions = Microsoft.AspNetCore.Identity.IdentityOptions; namespace LINGYUN.Abp.Account.Web.OpenIddict.Pages.Account { - /// - /// 重写登录模型,实现双因素登录 - /// [Dependency(ReplaceServices = true)] - [ExposeServices(typeof(LoginModel), typeof(OpenIddictSupportedLoginModel))] - public class TwoFactorSupportedLoginModel : OpenIddictSupportedLoginModel + [ExposeServices( + typeof(LINGYUN.Abp.Account.Web.Pages.Account.LoginModel), + typeof(TwoFactorSupportedLoginModel))] + public class TwoFactorSupportedLoginModel : LINGYUN.Abp.Account.Web.Pages.Account.LoginModel { + protected AbpOpenIddictRequestHelper OpenIddictRequestHelper { get; } public TwoFactorSupportedLoginModel( IAuthenticationSchemeProvider schemeProvider, IOptions accountOptions, IOptions identityOptions, IdentityDynamicClaimsPrincipalContributorCache identityDynamicClaimsPrincipalContributorCache, AbpOpenIddictRequestHelper openIddictRequestHelper) - : base(schemeProvider, accountOptions, identityOptions, identityDynamicClaimsPrincipalContributorCache, openIddictRequestHelper) + : base(schemeProvider, accountOptions, identityOptions, identityDynamicClaimsPrincipalContributorCache) { + OpenIddictRequestHelper = openIddictRequestHelper; } - protected async override Task> GetExternalProviders() + public async override Task OnGetAsync() { - var providers = await base.GetExternalProviders(); + LoginInput = new LoginInputModel(); - foreach (var provider in providers) + var request = await OpenIddictRequestHelper.GetFromReturnUrlAsync(ReturnUrl); + if (request?.ClientId != null) { - var localizedDisplayName = L[provider.DisplayName]; - if (localizedDisplayName.ResourceNotFound) - { - localizedDisplayName = L["AuthenticationScheme:" + provider.DisplayName]; - } + // TODO: Find a proper cancel way. + // ShowCancelButton = true; - if (!localizedDisplayName.ResourceNotFound) + LoginInput.UserNameOrEmailAddress = request.LoginHint; + + //TODO: Reference AspNetCore MultiTenancy module and use options to get the tenant key! + var tenant = request.GetParameter(TenantResolverConsts.DefaultTenantKey)?.ToString(); + if (!string.IsNullOrEmpty(tenant)) { - provider.DisplayName = localizedDisplayName.Value; + CurrentTenant.Change(Guid.Parse(tenant)); + Response.Cookies.Append(TenantResolverConsts.DefaultTenantKey, tenant); } } - return providers; - } - - protected override Task TwoFactorLoginResultAsync() - { - // 重定向双因素认证页面 - return Task.FromResult(RedirectToPage("SendCode", new - { - returnUrl = ReturnUrl, - returnUrlHash = ReturnUrlHash, - rememberMe = LoginInput.RememberMe - })); + return await base.OnGetAsync(); } } }