diff --git a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs index 8fb043c6a9..731c64fc52 100644 --- a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs +++ b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/AccountAppService.cs @@ -16,7 +16,6 @@ namespace Volo.Abp.Account protected IdentityUserManager UserManager { get; } protected IAccountEmailer AccountEmailer { get; } protected IdentitySecurityLogManager IdentitySecurityLogManager { get; } - protected IOptions IdentityOptions { get; } public AccountAppService( diff --git a/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs b/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs index 5e3ffad3fc..ec9f26179d 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs @@ -2,6 +2,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Volo.Abp.Account.Localization; using Volo.Abp.Account.Settings; using Volo.Abp.Account.Web.Areas.Account.Controllers.Models; @@ -27,12 +28,14 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers protected IdentityUserManager UserManager { get; } protected ISettingProvider SettingProvider { get; } protected IdentitySecurityLogManager IdentitySecurityLogManager { get; } + protected IOptions IdentityOptions { get; } public AccountController( SignInManager signInManager, IdentityUserManager userManager, ISettingProvider settingProvider, - IdentitySecurityLogManager identitySecurityLogManager) + IdentitySecurityLogManager identitySecurityLogManager, + IOptions identityOptions) { LocalizationResource = typeof(AccountResource); @@ -40,6 +43,7 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers UserManager = userManager; SettingProvider = settingProvider; IdentitySecurityLogManager = identitySecurityLogManager; + IdentityOptions = identityOptions; } [HttpPost] @@ -104,6 +108,7 @@ namespace Volo.Abp.Account.Web.Areas.Account.Controllers return new AbpLoginResult(LoginResultType.InvalidUserNameOrPassword); } + await IdentityOptions.SetAsync(); return GetAbpLoginResult(await SignInManager.CheckPasswordSignInAsync(identityUser, login.Password, true)); } diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/AccountPageModel.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/AccountPageModel.cs index 5fd2124f49..36564f9af8 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/AccountPageModel.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/AccountPageModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Volo.Abp.Account.Localization; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Abp.Identity; @@ -16,6 +17,7 @@ namespace Volo.Abp.Account.Web.Pages.Account public SignInManager SignInManager { get; set; } public IdentityUserManager UserManager { get; set; } public IdentitySecurityLogManager IdentitySecurityLogManager { get; set; } + public IOptions IdentityOptions { get; set; } protected AccountPageModel() { diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs index a499f21a6f..a69b186adc 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs @@ -186,6 +186,8 @@ namespace Volo.Abp.Account.Web.Pages.Account return RedirectToPage("./Login"); } + await IdentityOptions.SetAsync(); + var loginInfo = await SignInManager.GetExternalLoginInfoAsync(); if (loginInfo == null) { @@ -259,6 +261,8 @@ namespace Volo.Abp.Account.Web.Pages.Account protected virtual async Task CreateExternalUserAsync(ExternalLoginInfo info) { + await IdentityOptions.SetAsync(); + var emailAddress = info.Principal.FindFirstValue(AbpClaimTypes.Email); var user = new IdentityUser(GuidGenerator.Create(), emailAddress, emailAddress, CurrentTenant.Id); diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs index 0560197cd3..065573c137 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Register.cshtml.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Volo.Abp.Account.Settings; using Volo.Abp.Auditing; using Volo.Abp.Identity; @@ -124,6 +125,8 @@ namespace Volo.Abp.Account.Web.Pages.Account protected virtual async Task RegisterExternalUserAsync(ExternalLoginInfo externalLoginInfo, string emailAddress) { + await IdentityOptions.SetAsync(); + var user = new IdentityUser(GuidGenerator.Create(), emailAddress, emailAddress, CurrentTenant.Id); (await UserManager.CreateAsync(user)).CheckErrors(); diff --git a/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AccountAppService_Tests.cs b/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AccountAppService_Tests.cs index b11d19b7a6..1bd5b54f1f 100644 --- a/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AccountAppService_Tests.cs +++ b/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AccountAppService_Tests.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using Shouldly; using Volo.Abp.Identity; using Xunit; @@ -12,18 +13,22 @@ namespace Volo.Abp.Account private readonly IIdentityUserRepository _identityUserRepository; private readonly ILookupNormalizer _lookupNormalizer; private readonly IdentityUserManager _userManager; - + private readonly IOptions _identityOptions; + public AccountAppService_Tests() { _accountAppService = GetRequiredService(); _identityUserRepository = GetRequiredService(); _lookupNormalizer = GetRequiredService(); _userManager = GetRequiredService(); + _identityOptions = GetRequiredService>(); } [Fact] public async Task RegisterAsync() { + await _identityOptions.SetAsync(); + var registerDto = new RegisterDto { UserName = "bob.lee", diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/ExternalLoginProviderBase.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/ExternalLoginProviderBase.cs index 0898577e3d..c7efc3510b 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/ExternalLoginProviderBase.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/ExternalLoginProviderBase.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using Volo.Abp.Domain.Repositories; using Volo.Abp.Guids; using Volo.Abp.MultiTenancy; @@ -14,23 +15,28 @@ namespace Volo.Abp.Identity protected ICurrentTenant CurrentTenant { get; } protected IdentityUserManager UserManager { get; } protected IIdentityUserRepository IdentityUserRepository { get; } + protected IOptions IdentityOptions { get; } protected ExternalLoginProviderBase( IGuidGenerator guidGenerator, ICurrentTenant currentTenant, IdentityUserManager userManager, - IIdentityUserRepository identityUserRepository) + IIdentityUserRepository identityUserRepository, + IOptions identityOptions) { GuidGenerator = guidGenerator; CurrentTenant = currentTenant; UserManager = userManager; IdentityUserRepository = identityUserRepository; + IdentityOptions = identityOptions; } public abstract Task TryAuthenticateAsync(string userName, string plainPassword); public virtual async Task CreateUserAsync(string userName, string providerName) { + await IdentityOptions.SetAsync(); + var externalUser = await GetUserInfoAsync(userName); NormalizeExternalLoginUserInfo(externalUser, userName); diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs index 72c8a6ad74..f6bed1b914 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDataSeeder.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; using Volo.Abp.MultiTenancy; @@ -17,6 +18,7 @@ namespace Volo.Abp.Identity protected IdentityUserManager UserManager { get; } protected IdentityRoleManager RoleManager { get; } protected ICurrentTenant CurrentTenant { get; } + protected IOptions IdentityOptions { get; } public IdentityDataSeeder( IGuidGenerator guidGenerator, @@ -25,7 +27,8 @@ namespace Volo.Abp.Identity ILookupNormalizer lookupNormalizer, IdentityUserManager userManager, IdentityRoleManager roleManager, - ICurrentTenant currentTenant) + ICurrentTenant currentTenant, + IOptions identityOptions) { GuidGenerator = guidGenerator; RoleRepository = roleRepository; @@ -34,6 +37,7 @@ namespace Volo.Abp.Identity UserManager = userManager; RoleManager = roleManager; CurrentTenant = currentTenant; + IdentityOptions = identityOptions; } [UnitOfWork] @@ -45,6 +49,8 @@ namespace Volo.Abp.Identity Check.NotNullOrWhiteSpace(adminEmail, nameof(adminEmail)); Check.NotNullOrWhiteSpace(adminPassword, nameof(adminPassword)); + await IdentityOptions.SetAsync(); + var result = new IdentityDataSeedResult(); using (CurrentTenant.Change(tenantId)) diff --git a/modules/identity/test/Volo.Abp.Identity.AspNetCore.Tests/Volo/Abp/Identity/AspNetCore/FakeExternalLoginProvider.cs b/modules/identity/test/Volo.Abp.Identity.AspNetCore.Tests/Volo/Abp/Identity/AspNetCore/FakeExternalLoginProvider.cs index 6a54ccf7e3..66acc057a3 100644 --- a/modules/identity/test/Volo.Abp.Identity.AspNetCore.Tests/Volo/Abp/Identity/AspNetCore/FakeExternalLoginProvider.cs +++ b/modules/identity/test/Volo.Abp.Identity.AspNetCore.Tests/Volo/Abp/Identity/AspNetCore/FakeExternalLoginProvider.cs @@ -1,5 +1,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; using Volo.Abp.MultiTenancy; @@ -14,12 +16,14 @@ namespace Volo.Abp.Identity.AspNetCore IGuidGenerator guidGenerator, ICurrentTenant currentTenant, IdentityUserManager userManager, - IIdentityUserRepository identityUserRepository) + IIdentityUserRepository identityUserRepository, + IOptions identityOptions) : base( guidGenerator, currentTenant, userManager, - identityUserRepository) + identityUserRepository, + identityOptions) { } diff --git a/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityUserManager_Tests.cs b/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityUserManager_Tests.cs index 04f08ed266..e60227cafe 100644 --- a/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityUserManager_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityUserManager_Tests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Options; using Shouldly; using Volo.Abp.Uow; using Xunit; @@ -18,6 +19,7 @@ namespace Volo.Abp.Identity private readonly ILookupNormalizer _lookupNormalizer; private readonly IUnitOfWorkManager _unitOfWorkManager; private readonly IdentityTestData _testData; + protected IOptions _identityOptions { get; } public IdentityUserManager_Tests() { @@ -28,6 +30,7 @@ namespace Volo.Abp.Identity _lookupNormalizer = GetRequiredService(); _testData = GetRequiredService(); _unitOfWorkManager = GetRequiredService(); + _identityOptions = GetRequiredService>(); } [Fact] @@ -120,6 +123,8 @@ namespace Volo.Abp.Identity [Fact] public async Task AddDefaultRolesAsync_In_Same_Uow() { + await _identityOptions.SetAsync(); + await CreateRandomDefaultRoleAsync(); using (var uow = _unitOfWorkManager.Begin()) @@ -176,6 +181,8 @@ namespace Volo.Abp.Identity [Fact] public async Task AddDefaultRolesAsync_In_Different_Uow() { + await _identityOptions.SetAsync(); + await CreateRandomDefaultRoleAsync(); Guid userId; diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs index f892b034c8..eee4c001ed 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs @@ -33,6 +33,7 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity protected IStringLocalizer Localizer { get; } protected IHybridServiceScopeFactory ServiceScopeFactory { get; } protected AbpIdentityOptions AbpIdentityOptions { get; } + protected IOptions IdentityOptions { get; } public AbpResourceOwnerPasswordValidator( UserManager userManager, @@ -41,7 +42,8 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity ILogger> logger, IStringLocalizer localizer, IOptions abpIdentityOptions, - IHybridServiceScopeFactory serviceScopeFactory) + IHybridServiceScopeFactory serviceScopeFactory, + IOptions identityOptions) { UserManager = userManager; SignInManager = signInManager; @@ -50,6 +52,7 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity Localizer = localizer; ServiceScopeFactory = serviceScopeFactory; AbpIdentityOptions = abpIdentityOptions.Value; + IdentityOptions = identityOptions; } /// @@ -123,6 +126,7 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity string errorDescription; if (user != null) { + await IdentityOptions.SetAsync(); var result = await SignInManager.CheckPasswordSignInAsync(user, context.Password, true); if (result.Succeeded) {