当前位置: 首页 > 知识库问答 >
问题:

在DocuSign-Node.js中请求访问令牌

亢正德
2023-03-14

我遵循以下文件:https://account-d.docusign.com/oauth/token

我正在为回调API尝试以下操作:

router.get('/authGrantReturn', function(req, res){
    let query = req.query; 

    console.log("code: " + req.query.code);
    console.log("status: " + req.query.state);
    console.log("in authGrantReturn");

        return new Promise((resolve, reject)=>{
    try{


    let bodyData = {
            grant_type: 'authorization_code',
            code: req.query.code
        };


        console.log( "========code======")
        console.log(  req.query.code)
        console.log( "========/code======")

        let combination = `${integrationKey}:${secretKey}`;
        let b64Combination = Buffer.from(combination).toString('base64');

        console.log("combination "+ combination)
        console.log("b64Combination "+ b64Combination)

   fetch('https://account-d.docusign.com/oauth/token',{
        method: 'POST',
        headers: { 'Authorization': 'Basic ' + b64Combination, 

        'Content-Type': 'application/x-www-form-urlencoded' },
       body: bodyData
   })





    /* fetch('https://account-d.docusign.com/oauth/token?grant_type:authorization_code&code='+b64Combination,{
        method: 'GET',
        headers: { 'Authorization': 'Basic ${b64Combination}', 'Content-Type': 'application/x-www-form-urlencoded',  'Content-Encoding': 'gzip'}
    }) */
    .then(function (res) {

上面是url调用的回调函数,看起来像这样:https://account-d.docusign.com/oauth/auth?response_type=code

然而,我得到了“坏请求”,请求。查询代码是正确的,我不确定组合。

我错过了什么?

共有1个答案

施冠玉
2023-03-14

我对您的代码进行了目视检查,并提出了几点意见:

我建议您使用wait,而不是显式地处理promise对象。请注意,您的代码需要在一个async函数中才能使用wait,但这很容易做到。

我认为您的具体问题是您没有正确发送表单数据。请参阅此引用。

测试代码:

const bodyform = new FormData();
bodyform.append('grant_type', 'authorization_code');
bodyform.append('code', 'req.query.code');

console.log( "========code======")
console.log(  req.query.code)
console.log( "========/code======")

let combination = `${integrationKey}:${secretKey}`;
let b64Combination = Buffer.from(combination).toString('base64');

console.log("combination "+ combination);
console.log("b64Combination "+ b64Combination);

let res = await fetch('https://account-d.docusign.com/oauth/token',{
    method: 'POST',
    headers: { 'Authorization': 'Basic ' + b64Combination },
    body: bodyform
});

console.log( "========Results========"); console.log (res);

检查从DocuSign返回的状态值是否与将用户浏览器重定向到DocuSign标识服务时发送的值相同,这一点很重要。状态值可防止CSRF攻击。它必须是一个新的nonce值--随机且不可用。

您应该将fetch调用包装在try/catch块中。这将在等待捕捉错误时正常工作。

安全专家建议您在实现与安全相关的过程时使用库(库通常可用)。

对于ode.js,护照库非常受欢迎,DocuSign有一个护照策略。请看这个使用它的例子。

请参阅索引和DSAuthCodeGrant支持对象,该对象获取用户的名称、帐户ID、API基本url等。

 类似资料:
  • 客户端通过使用按附录B“application/x-www-form-urlencoded”格式在HTTP请求实体正文中发送下列UTF-8字符编码的参数向令牌端点发起请求: grant_type 必需的。值必须设置为“client_credentials”。 scope 可选的。如3.3节所述的访问请求的范围。 客户端必须如3.2.1所述与授权服务器进行身份验证。 例如,客户端使用传输层安全发起如

  • 客户端通过使用按附录B“application/x-www-form-urlencoded”格式在HTTP请求实体正文中发送下列UTF-8字符编码的参数向令牌端点发起请求: grant_type 必需的。值必须设置为“password”。 username 必需的。资源所有者的用户名。 password 必需的。资源所有者的密码。 scope 可选的。如3.3节所述的访问请求的范围。 如果客户端类

  • 客户端通过使用按附录B“application/x-www-form-urlencoded”格式在HTTP请求实体正文中发送下列UTF-8字符编码的参数向令牌端点发起请求: grant_type 必需的。值必须被设置为“authorization_code”。 code 从授权服务器收到的授权码。 redirect_uri 必需的,若“redirect_uri”参数如4.1.1节所述包含在授权请求

  • 我想获取JWT Access令牌用于Docuse,我尝试使用以下代码获取访问令牌,之后我通过访问令牌创建信封,我得到一个错误 “调用创建信封时出错: { ”错误代码“: ”AUTHORIZATION_INVALID_TOKEN“,”消息“:”提供的访问令牌已过期、已吊销或格式不正确。 我从这个链接DocuSign JWT访问令牌请求以上代码,在用户提到的工作代码,请告诉我我犯了什么错误,注意:我正

  • 我在同意的情况下为我的应用程序手动/php sdk创建了docusignjwt访问令牌,并在restapi的代码中使用了该访问令牌。访问令牌的到期时间为1小时。如何在不征求同意的情况下一次又一次地更新DocuSign jwt访问令牌?或者如何延长访问令牌的到期时间?

  • 我已经能够为我的Aws Cognito用户获取访问令牌(使用这个)。但我不知道如何使用它为带有Cognito authorizer的Api网关生成经过身份验证的请求。有人能分享一个示例片段吗?