Hosting ASOS with TestServer

一个人想着一个人 提交于 2019-12-05 21:40:49

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.

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.

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():

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!