diff --git a/src/Api/IdentityServer/ResourceOwnerPasswordValidator.cs b/src/Api/IdentityServer/ResourceOwnerPasswordValidator.cs index ef44f41ee3..1184b22c55 100644 --- a/src/Api/IdentityServer/ResourceOwnerPasswordValidator.cs +++ b/src/Api/IdentityServer/ResourceOwnerPasswordValidator.cs @@ -104,8 +104,8 @@ namespace Bit.Api.IdentityServer var httpContext = _httpContextAccessor.HttpContext; _userManager = httpContext.RequestServices.GetRequiredService>(); _identityOptions = httpContext.RequestServices.GetRequiredService>()?.Value ?? new IdentityOptions(); - _jwtBearerOptions = httpContext.RequestServices.GetRequiredService>()?.Value; _jwtBearerIdentityOptions = httpContext.RequestServices.GetRequiredService>()?.Value; + _jwtBearerOptions = Core.Identity.JwtBearerAppBuilderExtensions.BuildJwtBearerOptions(_jwtBearerIdentityOptions); } private void BuildSuccessResult(User user, ResourceOwnerPasswordValidationContext context) diff --git a/src/Core/Identity/JwtBearerAppBuilderExtensions.cs b/src/Core/Identity/JwtBearerAppBuilderExtensions.cs index 8f8b8e3ea0..b200f98678 100644 --- a/src/Core/Identity/JwtBearerAppBuilderExtensions.cs +++ b/src/Core/Identity/JwtBearerAppBuilderExtensions.cs @@ -23,7 +23,14 @@ namespace Bit.Core.Identity } var jwtOptions = app.ApplicationServices.GetRequiredService>().Value; + var options = BuildJwtBearerOptions(jwtOptions); + app.UseJwtBearerAuthentication(options); + return app; + } + + public static JwtBearerOptions BuildJwtBearerOptions(JwtBearerIdentityOptions jwtOptions) + { var options = new JwtBearerOptions(); // Basic settings - signing key to validate with, audience and issuer. @@ -53,9 +60,7 @@ namespace Bit.Core.Identity OnMessageReceived = JwtBearerEventImplementations.MessageReceivedAsync }; - app.UseJwtBearerAuthentication(options); - - return app; + return options; } } }