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

问题描述 投票:3回答:1

控制台应用程序试图获取发现

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

工作正常,但我正在试图弄清楚这个东西是如何工作的,我似乎无法捕获http流量。

如果我使用http://localhost.fiddler重定向到本地代理错误:

连接到localhost.fiddler时出错:5000 / .well-known / openid-configuration:需要HTTPS(没有使用HTTPS设置,错误消息误导!)

当我们尝试使用web-api进行身份验证时,在代码中稍后会奇怪

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

localhost.fiddler工作正常,现在这是在同一个console.app中运行,在program.cs中运行相同的文件。这让我陷入困境,为什么我不能捕获流量达到5000的HTTP!那有什么神秘之处呢?是否有另一种方法来查看进出Identity Server的神奇HTTP流量?

添加了启动类

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();
    }
}

添加Blog,如果我们可以解决这个问题,将更新它并提供信用。

c# asp.net-web-api fiddler identityserver4 oidc
1个回答
4
投票

正如您所知,您需要使用http://localhost.fiddler来通过fiddler路由localhost流量。但是,使用DiscoveryClient.GetAsync使用DiscoveryClient和默认策略。对于此情况,该默认策略具有以下重要设置:

  • RequireHttps = true
  • AllowHttpOnLoopback = true

因此,除非您查询环回地址,否则它需要https。怎么知道什么是环回地址?有DiscoveryPolicy.LoopbackAddresses财产。默认情况下,它包含:

  • “本地主机”
  • "127.0.0.1"

因此,您需要“HTTPS required”错误 - “localhost.fiddler”不被视为环回地址,默认策略要求https用于非环回地址。

所以要修复,你需要将RequireHttps设置为false,或者将“localhost.fiddler”添加到loopback地址列表:

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

如果你这样做 - 你会在fiddler中看到disovery请求,但它会失败(响应将包含错误),因为服务器将报告权限为“http://localhost:5000”并且您查询“http://localhost.fiddler:5000”。因此,您还需要覆盖策略中的权限:

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

现在它将按预期工作。

© www.soinside.com 2019 - 2024. All rights reserved.