从Oauth2 DocuSign API获取Userinfo隐式授权

时间:2016-12-21 01:14:11

标签: jquery ajax phonegap-build docusignapi

我在从Implicit Grant oauth2调用收到访问令牌(response_type = token)后尝试从DocuSign API获取userinfo。

我的代码如下所示:

request = $.ajax({
  type: 'GET',
     xhrFields: {withCredentials: true},
     beforeSend: function(xhr) {
      xhr.setRequestHeader('Authorization', DSaccesstoken);
       },
     url: DSuserurl 
   });

request.done (function (response, textStatus, jqXHR) {
 alert(response); 
 }

request.fail(function (jqXHR, textStatus, errorThrown){
   alert("Error retrieving DocuSign User Account Information: " + textStatus + " " + errorThrown + ". "); 
   });

});

几点...... DSaccesstoken是一个包含从Docusign'收到的承载访问令牌的变量。代码执行成功,但当它假设包含json时,响应数据看起来像html。我也试过datatype: 'json',但这也不起作用。我也尝试使用headers: {'Authorization': DSaccesstoken}代替beforeSend,但这也没有用。

我假设标题未正确传递给DocuSign,但我并非100%确定。有谁知道我做错了什么?仅供参考,我使用PhoneGap Build服务创建移动应用程序。

1 个答案:

答案 0 :(得分:0)

两件事:

  1. 标题应为{'授权':'持票人'+ DSaccesstoken}。
  2. 不允许从客户端使用DocuSign Rest API,但不允许使用CORS限制。如果您从类似浏览器的方面调用它,您可能会考虑设置代理服务器(例如使用节点)。该代理服务器将接收ajax调用并将它们重定向到DocuSign API。您可以使用DocuSign official NPM package