如何解决如何绕过OAuth2Introspection中的证书SSL验证?
我正在使用API,但每次尝试连接到该API时都会收到此错误:
Request starting HTTP/1.1 GET https://localhost:5061/api/machine
info: System.Net.Http.HttpClient.IdentityModel.AspNetCore.OAuth2Introspection.BackChannelHttpClientName.LogicalHandler[100]
Start processing HTTP request GET https://localhost:5001/.well-kNown/openid-configuration
info: System.Net.Http.HttpClient.IdentityModel.AspNetCore.OAuth2Introspection.BackChannelHttpClientName.ClientHandler[100]
Sending HTTP request GET https://localhost:5001/.well-kNown/openid-configuration
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
system.invalidOperationException: Error parsing discovery document from https://localhost:5001: Error connecting to https://localhost:5001/.well-kNown/openid-configuration. The SSL connection Could not be established,see inner exception..
at IdentityModel.AspNetCore.OAuth2Introspection.PostConfigureOAuth2Introspectionoptions.GetIntrospectionEndpointFromdiscoveryDocument(OAuth2Introspectionoptions options)
at IdentityModel.AspNetCore.OAuth2Introspection.PostConfigureOAuth2Introspectionoptions.InitializeIntrospectionClient(OAuth2Introspectionoptions options)
at IdentityModel.AspNetCore.OAuth2Introspection.OAuth2IntrospectionHandler.LoadClaimsForToken(String token)
at IdentityModel.AspNetCore.OAuth2Introspection.OAuth2IntrospectionHandler.HandleAuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context,String scheme)
at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context,String scheme)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 145.1044ms 500 text/plain
我正在使用 IdentityModel.AspNetCore.OAuth2Introspection ,但是没有配置JwtBearer中的Backchannel HTTP处理程序的选项。
我想绕过开发中的OAuth2Introspection中的证书验证,类似于下面的代码:
.AddOAuth2Introspection("introspection",options =>
{
// SOME INTROSPECTION CODES
options.BackchannelHttpHandler = new SocketsHttpHandler
{
SslOptions = new SslClientAuthenticationoptions
{
RemoteCertificateValidationCallback = (sender,certificate,chain,sslPolicyErrors) => true
}
};
// MORE INTROSPECTION CODES
});
解决方法
通过使用ConfigurePrimaryHttpMessageHandler
扩展方法解决了该问题
services.AddHttpClient(OAuth2IntrospectionDefaults.BackChannelHttpClientName)
.ConfigurePrimaryHttpMessageHandler(() =>
{
return new SocketsHttpHandler
{
SslOptions = new SslClientAuthenticationOptions
{
RemoteCertificateValidationCallback = (sender,certificate,chain,sslPolicyErrors) => true
}
};
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。