【问题标题】:Docusign - API connect JWT - consent_requiredDocusign - API 连接 JWT - 同意_必需
【发布时间】:2020-06-10 04:10:48
【问题描述】:

我的目标:获取令牌以发送数字签名请求(服务器到服务器)

环境:PHP、Symfony - 演示环境

这是我在运行以下代码时收到的错误:Error : "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();
    }
}

提前谢谢你

【问题讨论】:

  • 请删除对您的密钥和 IK 的引用。您不希望它在网络上浮动。
  • 在下面回答。如果它对您有帮助,请务必支持并接受。谢谢! ——

标签: php jwt docusignapi


【解决方案1】:

问题可能是您提供的用户 GUID 尚未获得同意。

关注this guide for obtaining consent,您应该一切顺利。

摘录:

当应用程序进行身份验证以代表某个应用程序执行操作时 用户,将要求该用户同意该范围集 (权限集)应用程序已请求,除非他们 之前已经同意。

要开始身份验证并获得同意,您的应用程序会重定向 用户浏览器访问 DocuSign 授权 URI。请注意,这 不是标准的 GET 请求,不能由 应用。相反,用户的浏览器被重定向到 授权请求 URI,请求从那里发送到 帐户服务器。

【讨论】:

    猜你喜欢
    • 2022-09-26
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-20
    • 2021-03-11
    • 2018-12-14
    相关资源
    最近更新 更多