IdentityServer4 .Net Core 3 TokenResponse Json is null



我有这个代码

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

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

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

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

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

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

services.AddSigningCredential("CN=localhost");

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

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

两台机器上的 etc/主机示例

192.168.0.1 your.local.domain

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

https://your.local.domain

最新更新