PHP 7.4、Windows Server 2012、IIS 8。
我一直在阅读 stackOverflow 和 docusign 自己的文档,但我无法通过 JWT 令牌请求。我试过了:
- 使用 jwt.io 的说明
- 手动构建 JWT 请求的说明
- 使用 SDK 方法 requestJWTApplicationToken
- 我能想到的 aud 标签的每一个变体
- 我已验证 account-d.docusign.com、应用程序 ID 和用户 ID
- 该应用程序已获得同意
- 我什至从头开始,创建了第二个应用程序,获得了同意,等等......
当我使用 SDK 时,我得到“issuer_not_found”。其他方法,“unsupported_grant_type”。
我整个星期都在研究这件事,但我还没有找到不会引发错误的情况组合。老板每天都在敲打我的笼子。
有人能让我越过这个障碍吗?
issuer_not_found:
// bring in the docusign SDK
require_once("./docusign/vendor/autoload.php");
// bring in the config file provided by the QuickStart on Docusign
require_once("$admin/esign/ds_config.php");
// use the docusign client namespace
use DocuSign\eSign\Client\ApiClient;
// create the SDK client object
$client = new ApiClient();
// get the private key, saved in a file after being copy/pasted from the application
$rsa_private_key = file_get_contents("$admin/esign/private.key");
// get the client_id a.k.a. app id from the config file provided by the QuickStart on Docusign
$client_id = $GLOBALS['JWT_CONFIG']['ds_client_id'];
// $user_id = $GLOBALS['JWT_CONFIG']['ds_impersonated_user_id'];
// call the SDK api for the application JWT token, lifted from the SDK sample code
$test = $client->requestJWTApplicationToken($client_id, $rsa_private_key);
// $test = $client->requestJWTUserToken($client_id, $user_id, $rsa_private_key);
// display the inevitable error message
echo('<pre>[97616] $test:' . print_r($test, 1)) . '</pre>';
unsupported_grant_type
use Firebase\JWT\JWT;
use GuzzleHttp\Client;
$header = ["alg"=>"RS256","typ"=>"JWT"];
$privateKey = file_get_contents($this->path_admin . "/esign/private.key");
// $publicKey = file_get_contents($this->path_admin . "/esign/public.key");
$expiration = strtotime(date("Y-m-d H:i:s", time()) . " +1 hours"); // subtract 12 hours
$payload = json_encode(array(
"iss" => $GLOBALS['JWT_CONFIG']['ds_client_id'],
"aud" => "account-d.docusign.net",
"iat" => time(),
"sub" => $GLOBALS['JWT_CONFIG']['ds_impersonated_user_id'],
"exp" => $expiration,
"scope" => "signature"
));
$jwt = JWT::encode($payload, $privateKey, 'RS256');
$client = new Client();
$response = $client->request('POST', 'https://account-d.docusign.com/oauth/token', [
'body' => json_encode([
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion' => $jwt
])
]);