From 8bb84aae0408a03e35388cec6770a7f9b408de4f Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 31 Dec 2020 15:08:06 +0800 Subject: [PATCH] Improved --- .../AbpOpenIdConnectExtensions.cs | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 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 4d16439880..e98280d19d 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 @@ -27,26 +27,18 @@ namespace Microsoft.Extensions.DependencyInjection configureOptions?.Invoke(options); - if(options.Events != null) - { - var authorizationCodeReceived = options.Events.OnAuthorizationCodeReceived; - options.Events.OnAuthorizationCodeReceived = receivedContext => - { - AbpOnAuthorizationCodeReceived(receivedContext); - return authorizationCodeReceived(receivedContext); - }; - } - else + options.Events ??= new OpenIdConnectEvents(); + var authorizationCodeReceived = options.Events.OnAuthorizationCodeReceived ?? (_ => Task.CompletedTask); + + options.Events.OnAuthorizationCodeReceived = receivedContext => { - options.Events = new OpenIdConnectEvents - { - OnAuthorizationCodeReceived = AbpOnAuthorizationCodeReceived - }; - } + SetAbpTenantId(receivedContext); + return authorizationCodeReceived.Invoke(receivedContext); + }; }); } - private static Task AbpOnAuthorizationCodeReceived(AuthorizationCodeReceivedContext receivedContext) + private static void SetAbpTenantId(AuthorizationCodeReceivedContext receivedContext) { var tenantKey = receivedContext.HttpContext.RequestServices .GetRequiredService>().Value.TenantKey; @@ -56,8 +48,6 @@ namespace Microsoft.Extensions.DependencyInjection receivedContext.TokenEndpointRequest.SetParameter(tenantKey, receivedContext.Request.Cookies[tenantKey]); } - - return Task.CompletedTask; } } }