简体   繁体   English

IdentityServer 4,试图用fiddler捕获流量?

[英]IdentityServer 4, trying to capture traffic with fiddler?

Console application trying to get discovery 控制台应用程序试图获取发现

var disco = await DiscoveryClient.GetAsync("http://localhost:5000");

Works fine, however i'm trying to figure out how this thing works and I cant seem to capture the http traffic. 工作正常,但我正在试图弄清楚这个东西是如何工作的,我似乎无法捕获http流量。

if i use http://localhost.fiddler to redirect to the local proxy Errors With: 如果我使用http://localhost.fiddler重定向到本地代理错误:

Error connecting to localhost.fiddler:5000/.well-known/openid-configuration: HTTPS required (it's not setup with HTTPS, the error msg is misleading!) 连接到localhost.fiddler时出错:5000 / .well-known / openid-configuration:需要HTTPS(没有使用HTTPS设置,错误消息误导!)

Strangely later in the code when we try to authenticate to web-api with 当我们尝试使用web-api进行身份验证时,在代码中稍后会奇怪

var response = await client.GetAsync("http://localhost.fiddler:5001/identity");

localhost.fiddler works fine, now this is running in the same console.app, in program.cs so the same file. localhost.fiddler工作正常,现在这是在同一个console.app中运行,在program.cs中运行相同的文件。 This is driving me potty why on earth can't I capture traffic going to 5000 it's HTTP!!! 这让我陷入困境,为什么我不能捕获流量达到5000的HTTP! so what mysteries are causing this ? 那有什么神秘之处呢? is there another way to view the magic http traffic going to and from Identity Server ? 是否有另一种方法来查看进出Identity Server的神奇HTTP流量?

Added Startup class 添加了启动类

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // configure identity server with in-memory stores, keys, clients and scopes
        services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddTestUsers(Config.GetUsers());
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseIdentityServer();
    }
}

added Blog , will update it and credit if we can resolve this. 添加了博客 ,如果我们可以解决此问题,将更新它并提供信用。

As you correctly figured out, you need to use, for example, http://localhost.fiddler , to route localhost traffic through fiddler. 正如您所知,您需要使用http://localhost.fiddler来通过fiddler路由localhost流量。 However, using DiscoveryClient.GetAsync uses DiscoveryClient with default policy. 但是,使用DiscoveryClient.GetAsync会将DiscoveryClient与默认策略配合使用。 That default policy has the following settings important for this case: 对于此情况,该默认策略具有以下重要设置:

  • RequireHttps = true RequireHttps = true
  • AllowHttpOnLoopback = true AllowHttpOnLoopback = true

So, it requires https unless you query loopback address. 因此,除非您查询环回地址,否则它需要https。 How it knows what is loopback address? 怎么知道什么是环回地址? There is DiscoveryPolicy.LoopbackAddresses property. DiscoveryPolicy.LoopbackAddresses属性。 By default it contains: 默认情况下,它包含:

  • "localhost" “本地主机”
  • "127.0.0.1" “127.0.0.1”

For that reason you have "HTTPS required" error - "localhost.fiddler" is not considered a loopback address, and default policy requires https for non-loopback addresses. 因此,您需要“HTTPS required”错误 - “localhost.fiddler”不被视为环回地址,默认策略要求https用于非环回地址。

So to fix, you need to either set RequireHttps to false, or add "localhost.fiddler` to loopback address list: 因此,要修复,您需要将RequireHttps设置为false,或者将“localhost.fiddler”添加到环回地址列表:

var discoClient = new DiscoveryClient("http://localhost.fiddler:5000");
discoClient.Policy.LoopbackAddresses.Add("localhost.fiddler");
//discoClient.Policy.RequireHttps = false;                        
var disco = await discoClient.GetAsync();

If you do this - you will see disovery request in fiddler, however it will fail (response will contain error), because server will report authority as " http://localhost:5000 " and you query " http://localhost.fiddler:5000 ". 如果你这样做 - 你将在fiddler中看到disovery请求,但它会失败(响应将包含错误),因为服务器将报告权限为“ http:// localhost:5000 ”并且您查询“ http://localhost.fiddler :5000 “。 So you also need to override authority in your policy: 因此,您还需要覆盖策略中的权限:

var discoClient = new DiscoveryClient("http://localhost.fiddler:5000");
discoClient.Policy.LoopbackAddresses.Add("localhost.fiddler");
discoClient.Policy.Authority = "http://localhost:5000";
var disco = await discoClient.GetAsync();

Now it will work as expected. 现在它将按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM