IdentityServer4的有效grant_type值与使用混合授权类型的客户端有什么关系?

aar*_*onR 4 postman identityserver4

我正在使用IdentityServer4软件包的1.0.0版本.

"IdentityServer4": "1.0.0"
Run Code Online (Sandbox Code Playgroud)

我创建了一个客户端

new Client
{
    ClientId = "MobleAPP",
    ClientName = "Moble App",
    ClientUri= "http://localhost:52997/api/",                    
    AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,

    ClientSecrets =
    {
        new Secret("SecretForMobleAPP".Sha256())
    },

    AllowedScopes =
    {
        IdentityServerConstants.StandardScopes.OpenId,
        IdentityServerConstants.StandardScopes.Profile,
        "api"
    },
    AllowOfflineAccess = true
}
Run Code Online (Sandbox Code Playgroud)

和范围/ ApiResources

public static IEnumerable<ApiResource> GetApiResources()
{
   return new List<ApiResource>
   {

      new ApiResource("api", "My API")

    };
}
Run Code Online (Sandbox Code Playgroud)

使用以下用户/ TestUser

public static List<TestUser> GetUsers()
{
        return new List<TestUser>
        {

            new TestUser
            {
                SubjectId = "2",
                Username = "bob",
                Password = "password",

                Claims = new []
                {
                    new Claim(JwtClaimTypes.Name, "Bob Smith")
                }
            }
        };
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试测试我从Postman设置的IdentityServer,并确定grant_type键值对的可能值.

当我将grant_type设置为client_credentials并且不确定grant_type值是否还有其他选项时,我可以成功连接.

将grant_type设置为client_credentials的工作邮递员配置

Mic*_*iey 15

简短的回答

client_credentials是使用混合和客户端凭据授权类型时,grant_type您可以直接对令牌端点使用的唯一值.


更长的答案

客户端凭据授权类型是唯一允许您直接命中令牌端点的类型,这是您在Postman示例中所做的.在这种情况下,身份验证是针对客户端本身 - 即您注册的应用程序完成的.

使用混合授权类型时,将对最终用户(使用您的应用程序的用户)进行身份验证.在这种情况下,您无法直接命中端点令牌,但您必须向IdentityServer 发出授权请求.

执行此操作时,您将不使用grant_type参数而是response_type参数来指示IdentityServer您期望的内容.response_type您可以在IdentityServer常量中找到使用混合授权类型时可能的值- 它们是字典中的最后3项:

  • code id_token,它将返回授权码和身份令牌
  • code token,返回授权码和访问令牌
  • code id_token token,为您提供授权码,身份令牌和访问令牌

获得授权代码后,您将能够通过命中令牌端点将其替换为访问令牌,并可能更新刷新令牌.

  • 我相信“密码”grand_type 还允许您直接访问令牌端点 (2认同)