IdentityServer 令牌颁发者声称颁发的 JWT 令牌中缺少端口号

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

我的本地开发 IdentityServer 发出的令牌有一个奇怪的问题(IdentityServer4 和 Duende IdentityServer 都会发生)。

我的本地开发计算机上的 IdentityServer 正在端口 44310 上运行,这在发现文档中正确反映了

enter image description here

但是,几天后,当我获得 JWT 访问令牌时,当我在 jwt.io 中检查它时,由于某种原因,发行者只是 https://localhost

enter image description here

因此它省略了端口,因此当我从调用客户端使用此令牌时,它会返回 Unauthorized 并显示消息 https://localhost is invalid Issuer。

奇怪的是,这种情况是在几天前才开始发生的(无法确定具体时间),因为我本地的 IdentityServer 代码已经几个月没有改变了。

更奇怪的是,在另一个具有完全相同的 Visual Studio 2022 版本并运行与我的 IdentityServer 项目完全相同的代码库的开发虚拟机上,它仍然可以正常工作(即,在JWT 令牌)。

有什么想法吗?

.net identityserver4 duende-identity-server
1个回答
0
投票

发现文档中的 URL 会根据调用 IdentityServer 的人而变化,因此当客户端调用 IdentityServer 和浏览器调用它时,您将看到不同的颁发者。

一种选择是将发行者设置为静态 URL,如下所示:

var isBuilder = builder.Services.AddIdentityServer(options =>
{
    options.IssuerUri = "https://identity";
    ...
}

您可能还需要覆盖客户端中使用的 URL,如下所示:

}).AddOpenIdConnect(options =>
{
    options.Authority = "https://localhost:7001";
    options.MetadataAddress = "http://identity:80/.well-known/openid-configuration";

    ...
    options.Events.OnRedirectToIdentityProvider = context =>
    {
        context.ProtocolMessage.IssuerAddress = "https://localhost:7001/connect/authorize";
        return Task.CompletedTask;
    };
});

您可以在我的博客文章中阅读完整的解释:Docker 容器中的 IdentityServer

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.