【发布时间】:2021-01-29 22:34:30
【问题描述】:
我正在尝试使用 Docusign JWT 身份验证获取访问令牌,但我总是得到:
{"error":"invalid_grant","error_description":"unsupported_grant_type"}
我仔细检查了所有数据(集成密钥、api 用户名等),它们都很好。 我遵循了 Docusign 指南中的所有步骤。
我不能 100% 确定的唯一部分是当我生成 JWT 令牌的签名时。 文档说:
The first two parts of the JWT are signed with your application's private key (using the RSA SHA-256 digital signature algorithm) as shown in the diagram.
这就是我生成签名的方式:
$header = [
'typ' => 'JWT',
'alg' => 'RS256'
];
$body = [
'iss' => getenv('INTEGRATION_KEY'),
'sub' => getenv('API_USERNAME'),
'iat' => time(),
'exp' => time() + 3600,
'aud' => str_replace('https://', '', getenv('AUTH_URL')),
'scope' => 'signature impersonation'
];
$signature = JWT::encode($body, file_get_contents(env('PRIVATE_KEY')), 'RS256');
$header = $this->base64url_encode(json_encode($header));
$body = $this->base64url_encode(json_encode($body));
$jwt = $header . '.' . $body . '.' . $signature;
正确吗? 如果不是,并且由于 JWT::encode 需要一个数组作为第一个参数,我应该如何使其工作?
这就是我请求访问令牌的方式:
return Http::withHeaders(
[
'Content-Type' => 'application/x-www-form-urlencoded'
]
)->post(
getenv('AUTH_URL') . '/oauth/token',
[
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion' => $jwt
]
);
谢谢!
【问题讨论】:
-
整个 JWT 令牌在编码时都在签名变量中,有标头、正文(base64)和签名。
-
你看github.com/docusign/code-examples-php了吗?它正在使用 PHP SDK 使用 JWT 流获取令牌等等......
标签: php jwt docusignapi