Browse Source

fix(openiddict): Fixed openiddict login model

- Modify base class source
pull/1220/head
colin 10 months ago
parent
commit
c2d078ca87
  1. 53
      aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Pages/Account/TwoFactorSupportedLoginModel.cs

53
aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Pages/Account/TwoFactorSupportedLoginModel.cs

@ -1,64 +1,57 @@
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using System.Collections.Generic; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Account.Web; using Volo.Abp.Account.Web;
using Volo.Abp.Account.Web.Pages.Account;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.OpenIddict; using Volo.Abp.OpenIddict;
using IdentityOptions = Microsoft.AspNetCore.Identity.IdentityOptions; using IdentityOptions = Microsoft.AspNetCore.Identity.IdentityOptions;
namespace LINGYUN.Abp.Account.Web.OpenIddict.Pages.Account namespace LINGYUN.Abp.Account.Web.OpenIddict.Pages.Account
{ {
/// <summary>
/// 重写登录模型,实现双因素登录
/// </summary>
[Dependency(ReplaceServices = true)] [Dependency(ReplaceServices = true)]
[ExposeServices(typeof(LoginModel), typeof(OpenIddictSupportedLoginModel))] [ExposeServices(
public class TwoFactorSupportedLoginModel : OpenIddictSupportedLoginModel 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( public TwoFactorSupportedLoginModel(
IAuthenticationSchemeProvider schemeProvider, IAuthenticationSchemeProvider schemeProvider,
IOptions<AbpAccountOptions> accountOptions, IOptions<AbpAccountOptions> accountOptions,
IOptions<IdentityOptions> identityOptions, IOptions<IdentityOptions> identityOptions,
IdentityDynamicClaimsPrincipalContributorCache identityDynamicClaimsPrincipalContributorCache, IdentityDynamicClaimsPrincipalContributorCache identityDynamicClaimsPrincipalContributorCache,
AbpOpenIddictRequestHelper openIddictRequestHelper) AbpOpenIddictRequestHelper openIddictRequestHelper)
: base(schemeProvider, accountOptions, identityOptions, identityDynamicClaimsPrincipalContributorCache, openIddictRequestHelper) : base(schemeProvider, accountOptions, identityOptions, identityDynamicClaimsPrincipalContributorCache)
{ {
OpenIddictRequestHelper = openIddictRequestHelper;
} }
protected async override Task<List<ExternalProviderModel>> GetExternalProviders() public async override Task<IActionResult> 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]; // TODO: Find a proper cancel way.
if (localizedDisplayName.ResourceNotFound) // ShowCancelButton = true;
{
localizedDisplayName = L["AuthenticationScheme:" + provider.DisplayName];
}
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; return await base.OnGetAsync();
}
protected override Task<IActionResult> TwoFactorLoginResultAsync()
{
// 重定向双因素认证页面
return Task.FromResult<IActionResult>(RedirectToPage("SendCode", new
{
returnUrl = ReturnUrl,
returnUrlHash = ReturnUrlHash,
rememberMe = LoginInput.RememberMe
}));
} }
} }
} }

Loading…
Cancel
Save