普通网友 2015-01-06 21:48
浏览 37
已采纳

使用PHP进行DocusignAPI身份验证:“未指定集成器密钥”

I'm working on my first DocuSign API implementation and I'm having trouble authenticating to the REST API.

Following the API docs, I can authenticate successfully through using curl on the command line:

$ curl --request GET 'https://demo.docusign.net/restapi/v2/login_information' --header 'Content-Type:application/json' --header 'Accept:application/json' --header 'X-DocuSign-Authentication:{"<redacted>", "Password": "<redacted>", "IntegratorKey": "<redacted>"}'
{
  "loginAccounts": [
    {
      "name": "<redacted>",
      "accountId": "<redacted>",
      "baseUrl": "https://demo.docusign.net/restapi/v2/accounts/<redacted>",
      "isDefault": "true",
      "userName": "<redacted>",
      "userId": "<redacted>",
      "email": "<redacted>",
      "siteDescription": ""
    }
  ]

However, when trying to authenticate using an HTTP request through PHP, I receive a '401 Unauthorized' response, with the body:

'{
  "errorCode": "PARTNER_AUTHENTICATION_FAILED",
  "message": "The specified Integrator Key was not found or is disabled. An Integrator key was not specified."
}'

I'm pretty sure I'm setting an IntegratorKey header. My PHP code looks like:

$request = new \http\Client\Request('GET', $url, $this->getHeaders());
$client = new \http\Client();
$client->enqueue($request)->send();
$response = $client->getResponse();

I'm using the pecl/http-v2 HTTP library (docs at: http://devel-m6w6.rhcloud.com/mdref/http )

$url evals to: 'https://demo.docusign.net/restapi/v2/login_information'

The header array looks like:

array (size=3)
    0 => string 'X-DocuSign-Authentication: {"Username": "<redacted>", "Password":  "<redacted>", "IntegratorKey": "<redacted>"}' (length=155)
    1 => string 'Content-Type: application/json' (length=30)
    2 => string 'Accept: application/json' (length=24)

It appears the API key isn't being received, even though I can see the proper headers are being sent. Any ideas what I'm doing wrong here? Thanks for your help!

Edit: Fixed a missing double-quote around the password field in the authentication header. I had accidentally removed it while redacting the password. The authentication header matches character-for-character with the header used in the (working) 'curl' command.

  • 写回答

2条回答 默认 最新

  • doucheng3811 2015-01-13 16:30
    关注

    At this point, it looks like the HTTP library I used is the source of the problem. I switched to GuzzleHttp and the API calls worked without issue.

    I suspect the array where I specified the headers was not given in the correct format. It could have been a key => value format instead, but I haven't had the time/interest in testing this. Guzzle seems to be more modern and is working, so I haven't bothered going back to the pecl package.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效