From 93fa5864afce19a91477a3a2847d1a7fefcb30f8 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 28 Aug 2020 14:17:43 +0800 Subject: [PATCH 1/5] Add formTenantResolveContributor --- .../AbpAspNetCoreMultiTenancyModule.cs | 3 ++- .../FormTenantResolveContributor.cs | 23 +++++++++++++++++++ .../MyProjectNameWebModule.cs | 21 +++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/FormTenantResolveContributor.cs diff --git a/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/AbpAspNetCoreMultiTenancyModule.cs b/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/AbpAspNetCoreMultiTenancyModule.cs index d757b2f5f8..1d0268556f 100644 --- a/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/AbpAspNetCoreMultiTenancyModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/AbpAspNetCoreMultiTenancyModule.cs @@ -5,7 +5,7 @@ using Volo.Abp.MultiTenancy; namespace Volo.Abp.AspNetCore.MultiTenancy { [DependsOn( - typeof(AbpMultiTenancyModule), + typeof(AbpMultiTenancyModule), typeof(AbpAspNetCoreModule) )] public class AbpAspNetCoreMultiTenancyModule : AbpModule @@ -15,6 +15,7 @@ namespace Volo.Abp.AspNetCore.MultiTenancy Configure(options => { options.TenantResolvers.Add(new QueryStringTenantResolveContributor()); + options.TenantResolvers.Add(new FormTenantResolveContributor()); options.TenantResolvers.Add(new RouteTenantResolveContributor()); options.TenantResolvers.Add(new HeaderTenantResolveContributor()); options.TenantResolvers.Add(new CookieTenantResolveContributor()); diff --git a/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/FormTenantResolveContributor.cs b/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/FormTenantResolveContributor.cs new file mode 100644 index 0000000000..5e70559f0c --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/FormTenantResolveContributor.cs @@ -0,0 +1,23 @@ +using System.Linq; +using Microsoft.AspNetCore.Http; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.AspNetCore.MultiTenancy +{ + public class FormTenantResolveContributor : HttpTenantResolveContributorBase + { + public const string ContributorName = "Form"; + + public override string Name => ContributorName; + + protected override string GetTenantIdOrNameFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) + { + if (httpContext.Request == null || !httpContext.Request.Form.Any()) + { + return null; + } + + return httpContext.Request.Form[context.GetAbpAspNetCoreMultiTenancyOptions().TenantKey]; + } + } +} diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs index 699db2cec0..c36e4f7dd9 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs @@ -1,12 +1,16 @@ using System; using System.IO; +using System.Linq; +using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication.OAuth.Claims; +using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using MyCompanyName.MyProjectName.Localization; using MyCompanyName.MyProjectName.MultiTenancy; @@ -16,6 +20,7 @@ using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.Swagger; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.OAuth; +using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.Client; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI; @@ -139,6 +144,22 @@ namespace MyCompanyName.MyProjectName.Web options.Scope.Add("MyProjectName"); options.ClaimActions.MapAbpClaimTypes(); + + options.Events = new OpenIdConnectEvents + { + OnAuthorizationCodeReceived = receivedContext => + { + var tenantKey = receivedContext.HttpContext.RequestServices + .GetRequiredService>().Value.TenantKey; + + if (receivedContext.HttpContext.Request != null && receivedContext.Request.Cookies.ContainsKey(tenantKey)) + { + receivedContext.TokenEndpointRequest.SetParameter(tenantKey, receivedContext.Request.Cookies[tenantKey]); + } + + return Task.CompletedTask; + } + }; }); } From b8ebd90818bfb51af2e821b7561b83ee6d8ed43b Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 28 Aug 2020 14:21:38 +0800 Subject: [PATCH 2/5] Update module template --- .../MyProjectNameWebHostModule.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs index f2da06d4c2..a043a373f8 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs @@ -4,10 +4,13 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; using System.IO; +using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Protocols.OpenIdConnect; using MyCompanyName.MyProjectName.Localization; using MyCompanyName.MyProjectName.MultiTenancy; @@ -15,6 +18,7 @@ using MyCompanyName.MyProjectName.Web; using StackExchange.Redis; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.OAuth; +using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.Client; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI; @@ -154,6 +158,22 @@ namespace MyCompanyName.MyProjectName options.ClaimActions.MapJsonKey(AbpClaimTypes.UserName, "name"); options.ClaimActions.DeleteClaim("name"); + + options.Events = new OpenIdConnectEvents + { + OnAuthorizationCodeReceived = receivedContext => + { + var tenantKey = receivedContext.HttpContext.RequestServices + .GetRequiredService>().Value.TenantKey; + + if (receivedContext.HttpContext.Request != null && receivedContext.Request.Cookies.ContainsKey(tenantKey)) + { + receivedContext.TokenEndpointRequest.SetParameter(tenantKey, receivedContext.Request.Cookies[tenantKey]); + } + + return Task.CompletedTask; + } + }; }); } @@ -231,7 +251,7 @@ namespace MyCompanyName.MyProjectName app.UseHttpsRedirection(); app.UseVirtualFiles(); app.UseRouting(); - app.UseAuthentication(); + app.UseAuthentication(); if (MultiTenancyConsts.IsEnabled) { From f2f9ba263cd831f7484f094ed5aa68f87d70a40a Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Mon, 31 Aug 2020 14:48:03 +0800 Subject: [PATCH 3/5] Added Volo.Abp.AspNetCore.Authentication.OpenIdConnect --- framework/Volo.Abp.sln | 7 +++ .../FodyWeavers.xml | 3 ++ .../FodyWeavers.xsd | 30 ++++++++++++ .../AbpOpenIdConnectExtensions.cs | 47 +++++++++++++++++++ ...etCore.Authentication.OpenIdConnect.csproj | 19 ++++++++ ...etCoreAuthenticationOpenIdConnectModule.cs | 14 ++++++ nupkg/common.ps1 | 1 + ...yCompanyName.MyProjectName.Web.Host.csproj | 2 +- .../MyProjectNameWebModule.cs | 20 ++------ ...yCompanyName.MyProjectName.Web.Host.csproj | 2 +- .../MyProjectNameWebHostModule.cs | 18 +------ 11 files changed, 127 insertions(+), 36 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/FodyWeavers.xml create mode 100644 framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/FodyWeavers.xsd create mode 100644 framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj create mode 100644 framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index 3811a80ee8..4dbec58b49 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -327,6 +327,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.GlobalFeatures", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.GlobalFeatures.Tests", "test\Volo.Abp.GlobalFeatures.Tests\Volo.Abp.GlobalFeatures.Tests.csproj", "{231F1581-AA21-44C3-BF27-51EB3AD5355C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Authentication.OpenIdConnect", "src\Volo.Abp.AspNetCore.Authentication.OpenIdConnect\Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj", "{DEFE3DB2-EA4F-4F90-87FC-B25D64427BC5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -973,6 +975,10 @@ Global {231F1581-AA21-44C3-BF27-51EB3AD5355C}.Debug|Any CPU.Build.0 = Debug|Any CPU {231F1581-AA21-44C3-BF27-51EB3AD5355C}.Release|Any CPU.ActiveCfg = Release|Any CPU {231F1581-AA21-44C3-BF27-51EB3AD5355C}.Release|Any CPU.Build.0 = Release|Any CPU + {DEFE3DB2-EA4F-4F90-87FC-B25D64427BC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DEFE3DB2-EA4F-4F90-87FC-B25D64427BC5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DEFE3DB2-EA4F-4F90-87FC-B25D64427BC5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DEFE3DB2-EA4F-4F90-87FC-B25D64427BC5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1138,6 +1144,7 @@ Global {2CD3B26A-CA81-4279-8D5D-6A594517BB3F} = {447C8A77-E5F0-4538-8687-7383196D04EA} {04F44063-C952-403A-815F-EFB778BDA125} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {231F1581-AA21-44C3-BF27-51EB3AD5355C} = {447C8A77-E5F0-4538-8687-7383196D04EA} + {DEFE3DB2-EA4F-4F90-87FC-B25D64427BC5} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/FodyWeavers.xml b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/FodyWeavers.xml new file mode 100644 index 0000000000..be0de3a908 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/FodyWeavers.xsd b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/FodyWeavers.xsd new file mode 100644 index 0000000000..3f3946e282 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs new file mode 100644 index 0000000000..4e0b11d2ec --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs @@ -0,0 +1,47 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication.OpenIdConnect; +using Microsoft.Extensions.Options; +using Volo.Abp.AspNetCore.MultiTenancy; + +namespace Microsoft.Extensions.DependencyInjection +{ + public static class AbpOpenIdConnectExtensions + { + public static AuthenticationBuilder AddAbpOpenIdConnect(this AuthenticationBuilder builder) + => builder.AddAbpOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, _ => { }); + + public static AuthenticationBuilder AddAbpOpenIdConnect(this AuthenticationBuilder builder, Action configureOptions) + => builder.AddAbpOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, configureOptions); + + public static AuthenticationBuilder AddAbpOpenIdConnect(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) + => builder.AddAbpOpenIdConnect(authenticationScheme, OpenIdConnectDefaults.DisplayName, configureOptions); + + public static AuthenticationBuilder AddAbpOpenIdConnect(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) + { + builder.AddOpenIdConnect(authenticationScheme, displayName, options => + { + options.Events = new OpenIdConnectEvents + { + OnAuthorizationCodeReceived = receivedContext => + { + var tenantKey = receivedContext.HttpContext.RequestServices + .GetRequiredService>().Value.TenantKey; + + if (receivedContext.HttpContext.Request != null && + receivedContext.Request.Cookies.ContainsKey(tenantKey)) + { + receivedContext.TokenEndpointRequest.SetParameter(tenantKey, + receivedContext.Request.Cookies[tenantKey]); + } + + return Task.CompletedTask; + } + }; + }); + + return builder; + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj new file mode 100644 index 0000000000..4c628c5323 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj @@ -0,0 +1,19 @@ + + + + + + + netcoreapp3.1 + + + + + + + + + + + + diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs new file mode 100644 index 0000000000..eddb41a2f7 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs @@ -0,0 +1,14 @@ +using Volo.Abp.Modularity; +using Volo.Abp.MultiTenancy; +using Volo.Abp.Security; + +namespace Volo.Abp.AspNetCore.Authentication.OpenIdConnect +{ + [DependsOn( + typeof(AbpSecurityModule), + typeof(AbpMultiTenancyModule))] + public class AbpAspNetCoreAuthenticationOpenIdConnectModule : AbpModule + { + + } +} diff --git a/nupkg/common.ps1 b/nupkg/common.ps1 index 58b8cf83cf..f900343344 100644 --- a/nupkg/common.ps1 +++ b/nupkg/common.ps1 @@ -29,6 +29,7 @@ $projects = ( "framework/src/Volo.Abp.ApiVersioning.Abstractions", "framework/src/Volo.Abp.AspNetCore.Authentication.JwtBearer", "framework/src/Volo.Abp.AspNetCore.Authentication.OAuth", + "framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect", "framework/src/Volo.Abp.AspNetCore", "framework/src/Volo.Abp.AspNetCore.MultiTenancy", "framework/src/Volo.Abp.AspNetCore.Mvc.Client", diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj index 777288a513..e1ed669566 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj @@ -20,7 +20,6 @@ - @@ -29,6 +28,7 @@ + diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs index c36e4f7dd9..4a9bc4b2d3 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs @@ -20,6 +20,7 @@ using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.Swagger; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.OAuth; +using Volo.Abp.AspNetCore.Authentication.OpenIdConnect; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.Client; using Volo.Abp.AspNetCore.Mvc.Localization; @@ -50,6 +51,7 @@ namespace MyCompanyName.MyProjectName.Web typeof(MyProjectNameHttpApiModule), typeof(MyProjectNameHttpApiClientModule), typeof(AbpAspNetCoreAuthenticationOAuthModule), + typeof(AbpAspNetCoreAuthenticationOpenIdConnectModule), typeof(AbpAspNetCoreMvcClientModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule), typeof(AbpAutofacModule), @@ -126,7 +128,7 @@ namespace MyCompanyName.MyProjectName.Web { options.ExpireTimeSpan = TimeSpan.FromDays(365); }) - .AddOpenIdConnect("oidc", options => + .AddAbpOpenIdConnect("oidc", options => { options.Authority = configuration["AuthServer:Authority"]; options.RequireHttpsMetadata = true; @@ -144,22 +146,6 @@ namespace MyCompanyName.MyProjectName.Web options.Scope.Add("MyProjectName"); options.ClaimActions.MapAbpClaimTypes(); - - options.Events = new OpenIdConnectEvents - { - OnAuthorizationCodeReceived = receivedContext => - { - var tenantKey = receivedContext.HttpContext.RequestServices - .GetRequiredService>().Value.TenantKey; - - if (receivedContext.HttpContext.Request != null && receivedContext.Request.Cookies.ContainsKey(tenantKey)) - { - receivedContext.TokenEndpointRequest.SetParameter(tenantKey, receivedContext.Request.Cookies[tenantKey]); - } - - return Task.CompletedTask; - } - }; }); } diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj index f9e00d53d3..e266e7ef35 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj @@ -13,13 +13,13 @@ - + diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs index a043a373f8..de907e72c2 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs @@ -139,7 +139,7 @@ namespace MyCompanyName.MyProjectName { options.ExpireTimeSpan = TimeSpan.FromDays(365); }) - .AddOpenIdConnect("oidc", options => + .AddAbpOpenIdConnect("oidc", options => { options.Authority = configuration["AuthServer:Authority"]; options.RequireHttpsMetadata = false; @@ -158,22 +158,6 @@ namespace MyCompanyName.MyProjectName options.ClaimActions.MapJsonKey(AbpClaimTypes.UserName, "name"); options.ClaimActions.DeleteClaim("name"); - - options.Events = new OpenIdConnectEvents - { - OnAuthorizationCodeReceived = receivedContext => - { - var tenantKey = receivedContext.HttpContext.RequestServices - .GetRequiredService>().Value.TenantKey; - - if (receivedContext.HttpContext.Request != null && receivedContext.Request.Cookies.ContainsKey(tenantKey)) - { - receivedContext.TokenEndpointRequest.SetParameter(tenantKey, receivedContext.Request.Cookies[tenantKey]); - } - - return Task.CompletedTask; - } - }; }); } From 501742596dd85d5701df9eaf286c86b225326c84 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 1 Sep 2020 09:31:46 +0800 Subject: [PATCH 4/5] Update templates --- .../DependencyInjection/AbpOpenIdConnectExtensions.cs | 7 ++++--- ...olo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj | 1 + .../AbpAspNetCoreAuthenticationOpenIdConnectModule.cs | 8 ++++---- .../MyCompanyName.MyProjectName.Web.Host.csproj | 1 - .../MyProjectNameWebModule.cs | 3 --- .../MyCompanyName.MyProjectName.Web.Host.csproj | 1 - .../MyProjectNameWebHostModule.cs | 6 ++---- 7 files changed, 11 insertions(+), 16 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs index 4e0b11d2ec..20341e0d1b 100644 --- a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication.OAuth.Claims; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.MultiTenancy; @@ -20,8 +21,10 @@ namespace Microsoft.Extensions.DependencyInjection public static AuthenticationBuilder AddAbpOpenIdConnect(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) { - builder.AddOpenIdConnect(authenticationScheme, displayName, options => + return builder.AddOpenIdConnect(authenticationScheme, displayName, options => { + options.ClaimActions.MapAbpClaimTypes(); + options.Events = new OpenIdConnectEvents { OnAuthorizationCodeReceived = receivedContext => @@ -40,8 +43,6 @@ namespace Microsoft.Extensions.DependencyInjection } }; }); - - return builder; } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj index 4c628c5323..30f56491c5 100644 --- a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj @@ -14,6 +14,7 @@ + diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs index eddb41a2f7..13a8fd5c04 100644 --- a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs @@ -1,12 +1,12 @@ -using Volo.Abp.Modularity; +using Volo.Abp.AspNetCore.Authentication.OAuth; +using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; -using Volo.Abp.Security; namespace Volo.Abp.AspNetCore.Authentication.OpenIdConnect { [DependsOn( - typeof(AbpSecurityModule), - typeof(AbpMultiTenancyModule))] + typeof(AbpMultiTenancyModule), + typeof(AbpAspNetCoreAuthenticationOAuthModule))] public class AbpAspNetCoreAuthenticationOpenIdConnectModule : AbpModule { diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj index e1ed669566..c2f4f602ea 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj @@ -27,7 +27,6 @@ - diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs index 4a9bc4b2d3..7939bf80d0 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs @@ -50,7 +50,6 @@ namespace MyCompanyName.MyProjectName.Web [DependsOn( typeof(MyProjectNameHttpApiModule), typeof(MyProjectNameHttpApiClientModule), - typeof(AbpAspNetCoreAuthenticationOAuthModule), typeof(AbpAspNetCoreAuthenticationOpenIdConnectModule), typeof(AbpAspNetCoreMvcClientModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule), @@ -144,8 +143,6 @@ namespace MyCompanyName.MyProjectName.Web options.Scope.Add("email"); options.Scope.Add("phone"); options.Scope.Add("MyProjectName"); - - options.ClaimActions.MapAbpClaimTypes(); }); } diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj index e266e7ef35..f80745bf4a 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyCompanyName.MyProjectName.Web.Host.csproj @@ -18,7 +18,6 @@ - diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs index de907e72c2..8e2aaf1187 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebHostModule.cs @@ -18,6 +18,7 @@ using MyCompanyName.MyProjectName.Web; using StackExchange.Redis; using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.OAuth; +using Volo.Abp.AspNetCore.Authentication.OpenIdConnect; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.Client; using Volo.Abp.AspNetCore.Mvc.Localization; @@ -51,7 +52,7 @@ namespace MyCompanyName.MyProjectName [DependsOn( typeof(MyProjectNameWebModule), typeof(MyProjectNameHttpApiClientModule), - typeof(AbpAspNetCoreAuthenticationOAuthModule), + typeof(AbpAspNetCoreAuthenticationOpenIdConnectModule), typeof(AbpAspNetCoreMvcClientModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule), typeof(AbpAutofacModule), @@ -155,9 +156,6 @@ namespace MyCompanyName.MyProjectName options.Scope.Add("email"); options.Scope.Add("phone"); options.Scope.Add("MyProjectName"); - - options.ClaimActions.MapJsonKey(AbpClaimTypes.UserName, "name"); - options.ClaimActions.DeleteClaim("name"); }); } From 8f34d3efa8fa78fb94e5b24e2a6d6779d317f01c Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 1 Sep 2020 09:47:32 +0800 Subject: [PATCH 5/5] Update AbpOpenIdConnectExtensions.cs --- .../DependencyInjection/AbpOpenIdConnectExtensions.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs index 20341e0d1b..56886f679e 100644 --- a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs @@ -42,6 +42,8 @@ namespace Microsoft.Extensions.DependencyInjection return Task.CompletedTask; } }; + + configureOptions?.Invoke(options); }); } }