You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP完成OAuth流程后调用DocuSign userinfo端点遇unauthorized_client错误

解决DocuSign OAuth "unauthorized_client" 错误

以下是针对你遇到的问题的排查和修复步骤:

  • 检查Basic Auth编码完整性
    确认$integration_key和$secret_key是完整无截断的(代码里的省略号要替换成实际完整密钥),拼接时不要加多余空格,base64编码后也不能有额外字符。

  • 修正POST参数格式
    你直接传数组给CURLOPT_POSTFIELDS会被curl编码成multipart/form-data,但DocuSign令牌端点要求application/x-www-form-urlencoded格式。必须用http_build_query()转换:

    $body = http_build_query(array(
        "grant_type" => "authorization_code",
        "code" => $_REQUEST['code']
    ));
    curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $body);
    
  • 验证授权码有效性
    授权码只能用一次,重复使用会触发错误。同时要确认$_REQUEST['code']是DocuSign返回的完整、未过期的授权码(有效期通常约10分钟)。

  • 核对回调URL配置
    在DocuSign开发者控制台中,应用的重定向URI必须和你发起授权请求时的redirect_uri完全一致,包括协议、域名、路径,大小写也不能错。不匹配会直接拒绝令牌请求。

  • 检查应用状态与权限
    确保你的DocuSign应用是激活状态,且OAuth权限范围(比如signature)包含获取用户信息所需的权限。

修改后的完整代码示例

$url = 'https://account.docusign.com/oauth/token'; 
$cURLConnection = curl_init($url);

curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURLConnection, CURLOPT_POST, true); // 用标准POST选项替代自定义请求方法

// 构建Basic Auth头部
$integration_key = '你的完整集成密钥';
$secret_key = '你的完整密钥';
$authHeader = base64_encode($integration_key . ':' . $secret_key);
$headers = array(
   "Authorization: Basic {$authHeader}",
   "Content-Type: application/x-www-form-urlencoded" // 显式指定内容类型
);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, $headers);

// 构建URL编码的请求体
$body = http_build_query(array(
    "grant_type" => "authorization_code",
    "code" => $_REQUEST['code']
));
curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $body);

// 执行请求并处理错误
$response = curl_exec($cURLConnection);
if(curl_errno($cURLConnection)) {
    echo 'CURL错误: ' . curl_error($cURLConnection);
} else {
    $access_token = json_decode($response, true);
    print_r($access_token);
}
curl_close($cURLConnection);

内容的提问来源于stack exchange,提问作者Mats Raemen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 00:35:31