Docusign - API 连接 JWT - consent_required
Docusign - API connect JWT - consent_required
我的目标:获取令牌以发送数字签名请求(服务器到服务器)
环境: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();
}
}
提前致谢
问题可能是您提供的用户 GUID 尚未同意。
关注this guide for obtaining consent,你应该可以开始了。
摘录:
When an application authenticates to perform actions on behalf of a
user, that user will be asked to grant consent for the set of scopes
(sets of permissions) that the application has requested unless they
have previously already granted that consent.
To begin authentication and obtain consent, your application redirects
the user's browser to the DocuSign authorization URI. Note that this
is not a standard GET request and cannot be directly sent by the
application. Instead, the user's browser is redirected to an
authorization request URI and the request is sent from there to the
account server.
我的目标:获取令牌以发送数字签名请求(服务器到服务器)
环境: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();
}
}
提前致谢
问题可能是您提供的用户 GUID 尚未同意。
关注this guide for obtaining consent,你应该可以开始了。
摘录:
When an application authenticates to perform actions on behalf of a user, that user will be asked to grant consent for the set of scopes (sets of permissions) that the application has requested unless they have previously already granted that consent.
To begin authentication and obtain consent, your application redirects the user's browser to the DocuSign authorization URI. Note that this is not a standard GET request and cannot be directly sent by the application. Instead, the user's browser is redirected to an authorization request URI and the request is sent from there to the account server.