IdentityServer4 Testserver could not found

后端 未结 1 1103
北荒
北荒 2021-01-12 13:00

I am writing a test to get a token from identity server4 using Microsoft.AspNetCore.TestHost

   var hostBuilder = new WebHostBuilder()
                  


        
相关标签:
1条回答
  • 2021-01-12 13:49

    The discovery client is obviously doing an external call to that actual address. You want it to call the test server that happens to "live" InMemory.

    Take a look at these tests here for IdentityServer4 that tests the discovery document.

    To answer your question though you need to use one of the overloaded methods for the DiscoveryClient that takes in a handler that would make the correct "call" to your InMemory test server. Below is an example of how this could be done.

    var server = new TestServer(hostBuilder);
    var handler = server.CreateHandler();
    var discoveryClient = new DiscoveryClient("http://localhost:5000", handler);
    var discoveryDocument = await discoveryClient.GetAsync();
    

    Also I highly recommend going over the IdentityServer4 integration tests if youre going to be doing some of your own tests like this.

    0 讨论(0)
提交回复
热议问题