我的目标:获取令牌以发送数字签名请求(服务器到服务器)
环境:PHP、Symfony - 演示环境
这是我在运行以下代码时收到的错误:错误:“consent_required”
我的代码:
class ServiceSignature
{
private $container;
private $accessToken;
private $accountId;
private $signerName;
private $signerEmail;
private $fileNamePath;
private $basePath;
private $appPath;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
$this->accountId = "dc295354-xxxx-xxxx-xxxx-f2e3a8813b1e";
$this->basePath = 'https://demo.docusign.net/restapi';
$this->appPath = $_ENV["FOLDER_UPDATE"];
$this->accessToken = "";
$this->private_key_path = "../docusign_private.pem";
$this->private_key = file_get_contents($this->private_key_path);
$this->cle_integration = "bdfeaf70-xxxx-xxxx-xxxx-8a2ed57eb7ef";
$this->audience = "account-d.docusign.com";
$this->permission_scopes= "signature impersonation";
$this->token = $this->getToken();
}
public function getToken()
{
$current_time = time ();
$_token = [
"iss" => $this->cle_integration,
"sub" => $this->accountId,
"aud" => $this->audience,
"scope" => $this->permission_scopes,
"nbf" => $current_time,
"exp" => $current_time + 60*1000
];
$jwt = JWT::encode($_token, $this->private_key, 'RS256');
$headers = ['Accept' => 'application/json'];
$data = ['grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer', 'assertion' => $jwt];
$body = Unirest\Request\Body::form($data);
$response = Unirest\Request::post("https://{$this->audience}/oauth/token", $headers, $body);
if (strpos($response->raw_body, '<html>') !== false) {
throw new Exception("An error response was received!\n\n");
}
$json = $response->body;
dump($json);
die();
}
}
先感谢您
LEATH