IdentityServer AccessToken 一台服务器到另一台服务器

IdentityServer AccessToken one server to another server

我在网络 API 和 windows 服务器“服务器 1”上有 IdentityServer4 应用程序 运行,我们正在使用“access_token”授权 API 称呼。 现在客户想要在另一个 windows 服务器“服务器 2”中部署 IdentityServer4 应用程序。我按照以下步骤进行操作。

1.Created 使用 openssl 的证书。

2.Converted .pfx 的证书和密码。

3.Added 下面的代码从 windows 存储

加载证书
X509Certificate2 cert = null;
            using (X509Store certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine))
            {
                certStore.Open(OpenFlags.ReadOnly);
                X509Certificate2Collection certCollection = certStore.Certificates.Find(
                    X509FindType.FindByThumbprint,
                    // for dev only
                    "57041fcc9086da18419999fbb9276bd59bd8d14a",false);

                    cert = certCollection[0];
            }          
            return cert;
  1. 将 .pfx 文件复制到服务器 1 和 2 并进行安装。

5.Now 我从服务器 2 生成 access_token 并将此令牌传递给网络 API(运行 在服务器 1 上)和指向 IdentityServer [的“权限” =52=] 在服务器 1 上。

但这不起作用,我收到“未经授权”错误。

它清楚地表明我在这里做错了。

请指导我,提前致谢

访问令牌请求:enter image description here

令牌响应:enter image description here

来自 2 个服务器的令牌比较:enter image description here

如果您有多个身份服务器,则它们必须共享相同的签名密钥。

看到是 page 关于键 material。

如果您使用 AddDeveloperSigningCredential,那么每台机器都会有一组不同的 private/public 密钥。

HTTPS 证书与令牌签名证书不同。如果这不是问题,则可能是客户端收到令牌时受众与预期受众不匹配。请检查 ValidateAudience 参数。为简单起见,令牌中的受众(aud 声明)应该与两个 IdentityServers 相同。

如果身份验证 类 对您没有帮助,那么您可以随时禁用此 class 中的所有令牌验证功能,然后一一启用它们以查明是什么原因造成的你有问题。

如果也可能是发行人问题,因为这两种代币有不同的问题,也许客户希望代币中有特定的发行人。也许你应该在两个 IdentityServers 前面放一个 load-balancer 以便它们具有相同的颁发者?