首页 > 解决方案 > 使用 authorization_code 授权类型请求令牌

问题描述

我想使用授权代码授予类型请求令牌,我在这里看到它:https ://identitymodel.readthedocs.io/en/latest/client/token.html#

var response = await client.RequestAuthorizationCodeTokenAsync(new AuthorizationCodeTokenRequest
{
    Address = IdentityServerPipeline.TokenEndpoint,

    ClientId = "client",
    ClientSecret = "secret",

    Code = code,
    RedirectUri = "https://app.com/callback",

    // optional PKCE parameter
    CodeVerifier = "xyz"
});

但我不知道在哪里code得到CodeVerifier

标签: asp.net.net-coreoauth-2.0identityserver4openid-connect

解决方案


如您所知,授权代码授予包含几个步骤,您需要从RFC 6749 - The OAuth2.0 Authorization Framework中阅读它们。

授权服务器使用之前提供的重定向 URI(在请求中或客户端注册期间)将用户代理重定向回客户端。重定向 URI 包括授权代码和客户端之前提供的任何本地状态。

RFC 文档中有一个流程图,可以帮助您弄清楚如何获得代码

总而言之:您的客户端应发送授权代码及其请求,然后您将代码发送到授权服务器并检查其有效性。


推荐阅读