[英]Hosting ASOS with TestServer
I have an OpenIdDict
authentication server which is based on AspNet.Security.OpenIdConnect.Server
. 我有一个
OpenIdDict
身份验证服务器,它基于AspNet.Security.OpenIdConnect.Server
。 The setup works as expected. 设置按预期工作。
Now to do some in process integration;system tests which span the whole backend architecture I use the TestServer
class. 现在做一些进程集成;跨越整个后端架构的系统测试我使用
TestServer
类。
Why I test like this is another question
为什么我这样测试是另一个问题
When I call an web api endpoint of my ressource server the authorization wants to load http://localhost/.well-known/openid-configuration
but fails. 当我调用我的资源服务器的web api端点时,授权想要加载
http://localhost/.well-known/openid-configuration
但是失败了。
{"IDX10803: Unable to obtain configuration from: ' http://localhost/.well-known/openid-configuration '."})
{“IDX10803:无法从以下位置获取配置:' http://localhost/.well-known/openid-configuration '。”})
This are the OpenIdConnectSettings I use for the Testing Environment: 这是我用于测试环境的OpenIdConnectSettings:
Can I get the server to emit the configuration or can I provide the configuration in an other way? 我可以让服务器发出配置,还是可以通过其他方式提供配置?
What's important to note with TestServer
is that everything happens in memory: no socket is open to handle the HTTP requests your application might send. 使用
TestServer
需要注意的是,所有内容都发生在内存中:没有打开套接字来处理应用程序可能发送的HTTP请求。
Unfortunately, the OpenID Connect client middleware (that uses HttpClient
internally) has no way to know that and tries to send a "real" HTTP request to OpenIddict to retrieve the discovery document. 不幸的是,OpenID Connect客户端中间件(内部使用
HttpClient
)无法知道并试图向OpenIddict发送“真实”HTTP请求以检索发现文档。
To work around this issue, the recommended approach is to replace the default backchannel handler used by the OIDC middleware to use the in-memory handler provided by TestServer.CreateHandler()
: 要解决此问题,建议的方法是替换OIDC中间件使用的默认反向通道处理程序,以使用
TestServer.CreateHandler()
提供的内存中处理程序:
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
Authority = "http://localhost:54540/",
RequireHttpsMetadata = false,
ClientId = "myClient",
ClientSecret = "secret_secret_secret",
BackchannelHttpHandler = server.CreateHandler()
});
Note: the same approach also applies to the JWT bearer middleware and the aspnet-contrib introspection middleware. 注意:同样的方法也适用于JWT承载中间件和aspnet-contrib内省中间件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.