diff --git a/modules/identity/Volo.Abp.Identity.sln b/modules/identity/Volo.Abp.Identity.sln index b6973a36ba..f84a829907 100644 --- a/modules/identity/Volo.Abp.Identity.sln +++ b/modules/identity/Volo.Abp.Identity.sln @@ -35,6 +35,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Identity.TestBase" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Identity.Domain.Tests", "test\Volo.Abp.Identity.Domain.Tests\Volo.Abp.Identity.Domain.Tests.csproj", "{588B6E38-323B-4251-AC21-5F67C815A44E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Identity.AspNetCore", "src\Volo.Abp.Identity.AspNetCore\Volo.Abp.Identity.AspNetCore.csproj", "{D5EFC912-75A0-4856-9B8D-DFDD4CD66BAB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -97,6 +99,10 @@ Global {588B6E38-323B-4251-AC21-5F67C815A44E}.Debug|Any CPU.Build.0 = Debug|Any CPU {588B6E38-323B-4251-AC21-5F67C815A44E}.Release|Any CPU.ActiveCfg = Release|Any CPU {588B6E38-323B-4251-AC21-5F67C815A44E}.Release|Any CPU.Build.0 = Release|Any CPU + {D5EFC912-75A0-4856-9B8D-DFDD4CD66BAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D5EFC912-75A0-4856-9B8D-DFDD4CD66BAB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D5EFC912-75A0-4856-9B8D-DFDD4CD66BAB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D5EFC912-75A0-4856-9B8D-DFDD4CD66BAB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -116,6 +122,7 @@ Global {7291DCF0-7AA2-41A6-9AA7-98C2E9D13222} = {9FACAF96-A681-4B36-A938-A37DCA0B7EC1} {D7F61598-E7CE-4DAB-99EA-C266F0423606} = {9FACAF96-A681-4B36-A938-A37DCA0B7EC1} {588B6E38-323B-4251-AC21-5F67C815A44E} = {9FACAF96-A681-4B36-A938-A37DCA0B7EC1} + {D5EFC912-75A0-4856-9B8D-DFDD4CD66BAB} = {AADC5A0A-F100-4511-87DE-B74E55F5B69B} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {05740D37-83CF-4041-9C2A-D89F1B3DB5A4} diff --git a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo.Abp.Identity.AspNetCore.csproj b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo.Abp.Identity.AspNetCore.csproj new file mode 100644 index 0000000000..12b84640c0 --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo.Abp.Identity.AspNetCore.csproj @@ -0,0 +1,21 @@ + + + + + + netstandard2.0 + Volo.Abp.Identity.AspNetCore + Volo.Abp.Identity.AspNetCore + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + + diff --git a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreModule.cs b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreModule.cs new file mode 100644 index 0000000000..388c0849b7 --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreModule.cs @@ -0,0 +1,38 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Identity.AspNetCore +{ + [DependsOn( + typeof(AbpIdentityDomainModule) + )] + public class AbpIdentityAspNetCoreModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services + .GetObject() + .AddDefaultTokenProviders() + .AddSignInManager(); + + //(TODO: Extract an extension method like IdentityBuilder.AddAbpSecurityStampValidator()) + context.Services.AddScoped(); + context.Services.AddScoped(typeof(SecurityStampValidator), provider => provider.GetService(typeof(AbpSecurityStampValidator))); + context.Services.AddScoped(typeof(ISecurityStampValidator), provider => provider.GetService(typeof(AbpSecurityStampValidator))); + + var options = context.Services.ExecutePreConfiguredActions(new AbpIdentityAspNetCoreOptions()); + + if (options.ConfigureAuthentication) + { + context.Services + .AddAuthentication(o => + { + o.DefaultScheme = IdentityConstants.ApplicationScheme; + o.DefaultSignInScheme = IdentityConstants.ExternalScheme; + }) + .AddIdentityCookies(); + } + } + } +} diff --git a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreOptions.cs b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreOptions.cs new file mode 100644 index 0000000000..ad42a23f9a --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreOptions.cs @@ -0,0 +1,10 @@ +namespace Volo.Abp.Identity.AspNetCore +{ + public class AbpIdentityAspNetCoreOptions + { + /// + /// Default: true. + /// + public bool ConfigureAuthentication { get; set; } = true; + } +} \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpSecurityStampValidator.cs b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSecurityStampValidator.cs similarity index 100% rename from modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpSecurityStampValidator.cs rename to modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpSecurityStampValidator.cs diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Microsoft/Extensions/DependencyInjection/AbpIdentityServiceCollectionExtensions.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Microsoft/Extensions/DependencyInjection/AbpIdentityServiceCollectionExtensions.cs index 5a59253205..c2d91eafd7 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Microsoft/Extensions/DependencyInjection/AbpIdentityServiceCollectionExtensions.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Microsoft/Extensions/DependencyInjection/AbpIdentityServiceCollectionExtensions.cs @@ -22,11 +22,6 @@ namespace Microsoft.Extensions.DependencyInjection services.TryAddScoped(); services.TryAddScoped(typeof(UserManager), provider => provider.GetService(typeof(IdentityUserManager))); - //AbpSecurityStampValidator - services.TryAddScoped(); - services.TryAddScoped(typeof(SecurityStampValidator), provider => provider.GetService(typeof(AbpSecurityStampValidator))); - services.TryAddScoped(typeof(ISecurityStampValidator), provider => provider.GetService(typeof(AbpSecurityStampValidator))); - //AbpUserStore services.TryAddScoped(); services.TryAddScoped(typeof(IUserStore), provider => provider.GetService(typeof(IdentityUserStore))); @@ -35,10 +30,10 @@ namespace Microsoft.Extensions.DependencyInjection services.TryAddScoped(); services.TryAddScoped(typeof(IRoleStore), provider => provider.GetService(typeof(IdentityRoleStore))); - return services.AddIdentity(setupAction) - .AddDefaultTokenProviders() + return services + .AddIdentityCore(setupAction) + .AddRoles() .AddClaimsPrincipalFactory(); - //return services.AddIdentityCore(setupAction); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo.Abp.Identity.Domain.csproj b/modules/identity/src/Volo.Abp.Identity.Domain/Volo.Abp.Identity.Domain.csproj index a151c385b9..bdf9c1edd0 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo.Abp.Identity.Domain.csproj +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo.Abp.Identity.Domain.csproj @@ -27,7 +27,7 @@ - + diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs index 9b639f4b34..6465fe692f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/AbpIdentityDomainModule.cs @@ -55,6 +55,7 @@ namespace Volo.Abp.Identity options.User.RequireUniqueEmail = true; }); + context.Services.AddObjectAccessor(identityBuilder); context.Services.ExecutePreConfiguredActions(identityBuilder); AddAbpIdentityOptionsFactory(context.Services); diff --git a/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/ProfileAppService_Tests.cs b/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/ProfileAppService_Tests.cs index c1f0518b49..fc0334ce05 100644 --- a/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/ProfileAppService_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/ProfileAppService_Tests.cs @@ -1,6 +1,5 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Shouldly; @@ -12,16 +11,12 @@ namespace Volo.Abp.Identity public class ProfileAppService_Tests : AbpIdentityApplicationTestBase { private readonly IProfileAppService _profileAppService; - private readonly IIdentityUserRepository _userRepository; - private readonly SignInManager _signInManager; private readonly IdentityTestData _testData; private ICurrentUser _currentUser; public ProfileAppService_Tests() { _profileAppService = GetRequiredService(); - _userRepository = GetRequiredService(); - _signInManager = GetRequiredService>(); _testData = GetRequiredService(); } diff --git a/nupkg/common.ps1 b/nupkg/common.ps1 index 3871b73a1e..ba244db63c 100644 --- a/nupkg/common.ps1 +++ b/nupkg/common.ps1 @@ -119,6 +119,7 @@ $projects = ( "modules/tenant-management/src/Volo.Abp.TenantManagement.Web", # modules/identity + "modules/identity/src/Volo.Abp.Identity.AspNetCore", "modules/identity/src/Volo.Abp.Identity.Application", "modules/identity/src/Volo.Abp.Identity.Application.Contracts", "modules/identity/src/Volo.Abp.Identity.Domain",