Identityserver4 在IdentityServer中,客户端机密和范围机密之间有什么区别?

Identityserver4 在IdentityServer中,客户端机密和范围机密之间有什么区别?,identityserver4,identityserver3,Identityserver4,Identityserver3,有人能解释一下这两者的区别吗?我了解客户的秘密,但范围秘密仍然不清楚。。。以及为什么需要存在范围秘密 虽然我发现它在某些方面有所帮助,但在解释两者之间的区别时,我没有发现它有所帮助。客户端机密用于授权访问。此端点使用客户端id和客户端密码,并允许您请求访问令牌 作用域机密用于授权访问。此端点使用作用域id和作用域机密,因为只有访问令牌中包含的作用域才允许对其进行内省。多亏了Scott Brady,我才能够回答我的问题。这是我发现的 客户机密 正如Scott Brady所说,当客户端应用程序调用。

有人能解释一下这两者的区别吗?我了解客户的秘密,但范围秘密仍然不清楚。。。以及为什么需要存在范围秘密


虽然我发现它在某些方面有所帮助,但在解释两者之间的区别时,我没有发现它有所帮助。

客户端机密用于授权访问。此端点使用客户端id和客户端密码,并允许您请求访问令牌


作用域机密用于授权访问。此端点使用作用域id和作用域机密,因为只有访问令牌中包含的作用域才允许对其进行内省。

多亏了Scott Brady,我才能够回答我的问题。这是我发现的

客户机密

正如Scott Brady所说,当客户端应用程序调用。您的客户端应用程序必须具有有效的客户端Id和客户端机密才能调用令牌端点

范围机密

但如果您的资源服务器需要调用IdentityServer呢?当资源服务器调用时会发生这种情况。当应用程序使用引用令牌或使用JWT的服务器端验证时,会发生这种情况。因此,假设经过身份验证的客户端调用资源服务器上的受保护端点。然后,资源服务器必须使用IdentityServer验证JWT承载令牌。但是,从资源服务器发送到IdentityServer的请求必须是受保护的调用。也就是说,为了使用内省端点,资源服务器必须向IdentityServer提供JWT承载令牌。资源服务器无法使用它正在尝试验证的令牌,因为该令牌属于客户端(访问群体不针对资源服务器,而是针对客户端应用程序)。此外,资源服务器甚至不确定承载令牌是否有效。资源服务器使用相关的承载令牌来验证验证所述承载令牌的请求是没有意义的。所以现在有一个问题。。。资源服务器如何向IdentityServer发送经过身份验证的请求

这就是范围秘密的来源。IdentityServer解决此问题的方法是允许您创建包含作用域机密的作用域。此作用域添加到资源服务器身份验证选项中。例如:

app.UseIdentityServerBearerTokenAuthentication(
                new IdentityServerBearerTokenAuthenticationOptions
                {
                    Authority = "http://localhost:5000",
                    ClientId = "api", //The Scope name
                    ClientSecret = "api-secret", //This is the non hashed/encrypted Scope Secret
                    RequiredScopes = new[] { "api" } //Must add the Scope name here
                });
通过使此作用域成为必需的,我们可以确保任何经过身份验证的客户端应用程序都具有此作用域。然后在IdentityServer中添加作用域,如下所示:

new Scope
    {
        Name = "api",
        DisplayName = "Scope DisplayName",
        Description = "This will grant you access to the API",

        //The secret here must be Sha256-ed in order for the /introspection end point to work.
        //If the API's IdentityServerBearerTokenAuthenticationOptions field is set as so ValidationMode = ValidationMode.ValidationEndpoint,
        //then the API will call the /introspection end point to validate the token on each request (instead of ValidationModel.ValidationLocal.
        //The ClientSecret must be the NON Sha256-ed string (for example Api = "api-secret" then scope secret must = "api-secret".Sha256())
        //for the token to be validated. There must be a Scope that has the same name as the ClientId field in IdentityServerBearerTokenAuthenticationOptions.
        //This is an API authenticates with IdentityServer
         ScopeSecrets = new List<Secret>
                         {
                              new Secret("api-secret".Sha256())
                         },
          Type = ScopeType.Resource
      }
新范围
{
Name=“api”,
DisplayName=“Scope DisplayName”,
Description=“这将授予您访问API的权限”,
//这里的秘密必须隐藏起来,这样内省的终点才能起作用。
//如果API的IdentityServerBealerTokenAuthenticationOptions字段设置为so ValidationMode=ValidationMode.ValidationEndpoint,
//然后API将调用/introspection端点来验证每个请求上的令牌(而不是ValidationModel.ValidationLocal)。
//ClientSecret必须是非Sha256加密字符串(例如Api=“Api secret”然后scope secret必须=“Api secret”.Sha256())
//对于要验证的令牌,必须有一个与IdentityServerBealerTokenAuthenticationOptions中的ClientId字段同名的作用域。
//这是一个使用IdentityServer进行身份验证的API
ScopeSecrets=新列表
{
新秘密(“api秘密”.Sha256())
},
Type=ScopeType.Resource
}
因此,当资源服务器调用内省端点时,它将简单地使用范围机密作为客户端机密,使用范围名称作为客户端Id