首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Google脚本获取文档的访问令牌

问使用Google脚本获取文档的访问令牌
EN

Stack Overflow用户
提问于 2021-09-15 08:26:46
回答 1查看 209关注 0票数 1

我正在使用Google脚本绑定以获得访问令牌。

参考文献:https://developers.docusign.com/platform/auth/jwt/jwt-get-token/

使用Postman,我可以通过使用下面的URL:https://account-d.docusign.com/oauth/token和正文中的以下两个字段发送请求来获得访问令牌:

  • grant_type : urn:ietf:params:oauth:grant-type:jwt-bearer
  • assertion : MY_JSON_WEB_TOKEN

如何在Apps脚本中复制它?

经过无数个小时的尝试和错误,我仍然得到了这个错误:{"error":"invalid_grant","error_description":"unsupported_grant_type"}

剧本:

代码语言:javascript
复制
function obtainAccessToken(){
  const JWT = MY_JSON_WEB_TOKEN;

  const URL = 'https://account-d.docusign.com/oauth/token';

  const PARAMS = {
    "muteHttpExceptions": true,
    "method": "POST",
    "contentType": "application/json",
    "payload": {
      "body":{
        "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
        "assertion": JWT
      }
    } 
  };

  return UrlFetchApp.fetch(URL, PARAMS);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-15 09:24:47

这是正确的功能:

代码语言:javascript
复制
function obtainAccessToken(){
  const JWT = MY_JSON_WEB_TOKEN;

  const URL = 'https://account-d.docusign.com/oauth/token';

  const PARAMS = {
    "method": "POST",
    "headers":{
      "Accept": "application/json",
      "contentType": "application/x-www-form-urlencoded"
    },
    "payload": {
      "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
      "assertion": JWT
    } 
  };

  return UrlFetchApp.fetch(URL, PARAMS);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69189577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档