Thinktecture Identity Server 3:保护 WEB API 免遭未经授权访问的客户端机密

Thinktecture Identity Server 3: Client Secrets to protect WEB APIs from unauthorized access

我正在使用 JS 应用程序遍历代码示例并尝试了解如何确保系统安全。

AFAIK,在将令牌传递到资源 API 服务器以允许访问后,必须验证在身份服务器范围内提供的秘密。

因此,在身份服务器上,我们为 "api" 资源范围设置了一个秘密,例如:

      new Scope
            {
                Name = "api",
                DisplayName = "Access to API",
                Description = "This will grant you access to the API",
                ScopeSecrets = new List<Secret>
                {
                    new Secret("api-secret".Sha256())
                },
                Type = ScopeType.Resource
            },

在资源 APIs 上,我们必须验证此令牌是否由受信任的颁发者授予:

  // Wire token validation
        app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
        {
            Authority = "https://localhost:44300",

            ClientId = "api",
            //ClientSecret = "api-secret",
            ClientSecret = "api-secret-changed",

            RequiredScopes = new[] { "api" }
        });

但是,我已经按照代码更改了 ClientSecret,但用户仍然经过身份验证,我可以访问所有声明。

那么,令牌验证的秘密机制是如何工作的?

除了提供给范围 API 的秘密之外,我们还需要在客户端级别提供秘密吗?

作用域上的机密用于与内省端点通信。

如果令牌是引用令牌,或者如果令牌验证中间件上的验证模式明确设置为 ValidationEndpoint,则使用自省。