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 56886f679e..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 @@ -25,26 +25,29 @@ namespace Microsoft.Extensions.DependencyInjection { options.ClaimActions.MapAbpClaimTypes(); - options.Events = new OpenIdConnectEvents + configureOptions?.Invoke(options); + + options.Events ??= new OpenIdConnectEvents(); + var authorizationCodeReceived = options.Events.OnAuthorizationCodeReceived ?? (_ => Task.CompletedTask); + + options.Events.OnAuthorizationCodeReceived = receivedContext => { - 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; - } + SetAbpTenantId(receivedContext); + return authorizationCodeReceived.Invoke(receivedContext); }; - - configureOptions?.Invoke(options); }); } + + private static void SetAbpTenantId(AuthorizationCodeReceivedContext receivedContext) + { + var tenantKey = receivedContext.HttpContext.RequestServices + .GetRequiredService>().Value.TenantKey; + + if (receivedContext.Request.Cookies.ContainsKey(tenantKey)) + { + receivedContext.TokenEndpointRequest.SetParameter(tenantKey, + receivedContext.Request.Cookies[tenantKey]); + } + } } }