2017-01-23 49 views

回答

4

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

范围秘密用于授权访问introspection endpoint。此端点使用作用域标识和作用域秘密,因为只有包含在访问标识中的作用域才允许对其进行自省。

6

感谢Scott Brady,我能够回答我的问题。下面是我发现了什么......

客户端秘密

正如Scott Brady说,当你的客户端应用程序调用token end point客户端秘密被使用。这种方式只有授权的客户端应用程序才能访问端点。您的客户端应用程序必须具有有效的客户端ID和客户端密钥才能调用令牌端点。

范围秘密

但是,如果你的资源服务器需要调用IdentityServer?当资源服务器调用access token end point时会发生这种情况。当您的应用程序使用引用令牌时(这必须通过调用访问令牌端点来验证),或者您已选择通过验证端点验证JWT,则会发生这种情况。因此,假设您的身份验证客户端调用资源服务器上的受保护端点。资源服务器必须使用auth服务器(您正在使用的IdentityServer实施)验证该令牌。但是,从资源服务器发送到auth服务器的请求必须具有身份验证信息。如果你的资源服务器使用了它试图验证的身份验证方式的相同访问令牌,这将是愚蠢的(并且违反了协议)。所以现在有一个问题...资源服务器如何发送验证请求的验证信息?

这是范围秘密进来的地方。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 since it has to be required 
       }); 

通过使该范围需要,我们可以确保任何身份验证客户端应用程序都会有这个范围。资源服务器对令牌验证端点时,它会简单地使用范围秘密作为客户端密钥和范围的名称作为客户端调用所以当

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 = "spi-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 
     } 

:然后在IdentityServer将添加范围,像这样ID。

相关问题