【发布时间】:2015-02-22 22:55:43
【问题描述】:
我有一个 AngularJS 应用程序,它利用 DocuSign 嵌入式签名 REST API 在用户填写表单后打开一个选项卡,其中包含嵌入到 DocuSign 的文档。
我在 StackOverflow 上查看了一些可以提供帮助的主题,但找不到与我的实现类似的东西。
我在登录时继续收到 401 错误,我很确定这是因为 CORS 被阻止。 任何帮助表示赞赏!
这是我的 DocuSign 工厂:
app.factory('dsFactory', function($http) {
return {
login: function(templateId) {
return $http({
url: 'https://demo.docusign.net/restapi/v2/login_information',
method: 'GET',
params: {
'X-DocuSign-Authentication': {
'DocuSignCredentials': {
'UserName': 'xxx',
'Password': 'xxx',
'IntegratorKey': 'xxx'
}
}
}
});
},
envelope: function(baseUrl, templateId, recipientName, templateRoleName) {
var url = baseUrl + "/envelopes";
return $http({
url: url,
method: 'POST',
params: {
"emailSubject": "DocuSign API call - Embedded Sending Test",
"templateId": templateId,
"templateRoles": [{
"email": "xxx",
"name": recipientName,
"roleName": templateRoleName
}],
"status": "sent"
}
});
},
getUrl: function(baseUrl, envelopeId, recipientName) {
var url = baseUrl + "/envelopes/" + envelopeId + "/views/recipient";
return $http({
url: url,
method: 'POST',
params: {
"returnUrl": "http://www.docusign.com/devcenter",
"authenticationMethod": "email",
"email": "xxx",
"userName": recipientName
}
});
}
};
});
这是使用嵌入文档视图打开新选项卡的承诺链:
// Elaborate promise chain for DocuSign login and document url retrieval
loginPromise = dsFactory.login($scope.templateId);
loginPromise.then(
function(payload) {
$scope.dsBaseUrl = payload.data.loginAccounts[0].baseUrl;
envelopePromise = dsFactory.envelope($scope.dsBaseUrl, $scope.templateId, $scope.businessName, 'Signer');
envelopePromise.then(
function(payload) {
$scope.dsEnvelopeId = payload.data.envelopeId;
urlPromise = dsFactory.getUrl($scope.dsBaseUrl, $scope.dsEnvelopeId, $scope.businessName);
urlPromise.then(
function(payload) {
$scope.dsCompleteUrl = payload.data.returnUrl;
window.open($scope.dsCompleteUrl);
},
function(errorPayload) {
console.log('retrieve DS url failed' + '\n');
console.log('Status: ' + errorPayload.status);
}
);
},
function(errorPayload) {
console.log('retrieve DS envelopeId failed' + '\n');
console.log('Status: ' + errorPayload.status);
}
);
},
function(errorPayload) {
console.log('DS login failed' + '\n');
console.log('Status: ' + errorPayload.status);
}
);
关于如何让这种集成发挥作用有什么想法或帮助吗?
可能与标题有关?
【问题讨论】:
标签: javascript angularjs csrf docusignapi