【问题标题】:IdentityServer4 .Net Core 3 TokenResponse Json is nullIdentityServer4 .Net Core 3 TokenResponse Json 为空
【发布时间】:2019-10-16 23:00:27
【问题描述】:

我有这个代码

class Program
{
    static async Task Main(string[] args)
    {
        HttpClient Client = new HttpClient();

        var disco = await Client.GetDiscoveryDocumentAsync("https://intranet.mycompany.com/");

        if (disco.IsError)
        {
             Console.WriteLine(disco.Error);
            return;
        }

        // request token
        var tokenResponse = await Client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
        {
            Address = disco.TokenEndpoint,
            ClientId = "Console",
            ClientSecret = "secret",
            Scope = "dev_api",
        });

        if (tokenResponse.IsError)
        {
            Console.WriteLine(tokenResponse.Error);
            return;
        }

        Console.WriteLine(tokenResponse.Json);
        Console.WriteLine("\n\n");
    }
}

我们只是在 etc/host 上设置了 intranet.mycompany.com 来提供本地 IP 地址,并且我们设置了一个自签名证书。 GetDiscoveryDocumentAsync 工作正常,它连接到 IdentityServer,但 RequestClientCredentialsTokenAsync 返回 BAD REQUEST

{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:

{ 缓存控制:无缓存 Pragma:无缓存 传输编码:分块 服务器:Microsoft-IIS/10.0 日期:2019 年 10 月 14 日星期一 15:31:42 GMT 过期:-1 }}

关于如何使用自签名证书通过 IP 地址在本地网络上设置身份服务器 4 .core 3 的任何指导?我想为我们的客户在 localhost 之外创建一个演示基础架构,以便我们以后可以在客户站点上发布。

【问题讨论】:

  • 来自 IdentityServer 的 BadRequest 包含有关请求失败原因的信息,这些信息在“tokenResponse.Error”中可用。那么错误是什么?可能是客户端“控制台”未配置为使用客户端凭据授予类型,或者客户端本身可能根本未配置。发现文件的可用性与此无关。与令牌请求不同,它是一个没有限制的公共文档。
  • Error 为 null,ErrorType 为“Protocol”,所以 localmachine 上的intranet.mycompany.com 无效?
  • 协议错误可能表明发行者(创建令牌的人)、受众(可能接受令牌的人)或有效时间间隔(但可能并非如此)无效。所以这就是看的地方。从 IdentityServer(客户端/范围/资源)检查您的配置,并与 Api/Client 启动中的配置进行比较。
  • 如果我将 URL 更改为 localhost 它工作正常。在 localhost 之外设置环境的任何指导,例如带有自签名证书的 https://

标签: identityserver4 .net-core-3.0


【解决方案1】:

所以我意外地想出了如何使用 HTTPS 解决本地网络的这种情况。您必须有 1 个名为 localhost 的自签名证书才能在身份服务器启动类 ConfigureServices 中使用

services.AddSigningCredential("CN=localhost");

然后您必须拥有另一个名为 your.local.domain 的自签名证书,并在 etc/host 文件中设置该域。您还必须使用此证书为身份服务器站点设置您的 Web 服务器。

如果您想从本地网络中的其他计算机连接到身份服务器,您必须复制您的 your.local.domain 并将其安装在该计算机上。您还必须在该机器上设置 etc/host 文件以重定向到 Web 服务器。

两台机器上的 etc/host 示例

192.168.0.1 your.local.domain

身份服务器的工作 ULR 将是这样的

https://your.local.domain

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多