【问题标题】:Requesting access token to Zoom API via Oauth - error 'missing grant type'通过 Oauth 请求 Zoom API 的访问令牌 - 错误“缺少授权类型”
【发布时间】:2021-06-09 11:31:29
【问题描述】:

我正在尝试通过 Oauth 从 Zoom api 接收访问令牌。无论我尝试以什么形式发送正文,'Content-Type': 'application/json' 或 Content-Type:application/x-www-form-urlencoded,它总是出错{原因:'缺少授权类型' ,错误:'invalid_request' }。

var options = {
  method: "POST",
  url: "https://zoom.us/oauth/token",
  body: JSON.stringify({
    grant_type: "authorization_code",
    code: process.env.AUTH_CODE,
  }),
  redirect_uri: "https://zoom.us",
};

var header = {
  headers: {
    Authorization:
      "Basic " +
      Buffer.from(process.env.ID + ":" + process.env.SECRET).toString("base64"),
  },
  "Content-Type": "application/json",
};

var tokCall = () =>
  axios
    .post("https://zoom.us/oauth/token", options, header)
    .then((response) => {
      console.log(response);
    })
    .catch((error) => {
      console.log(error.response);
    });

tokCall();

我相当确定答案在于 Oauth 接收数据的数据类型,或者它在哪里/是否在接收正文。如有任何建议,我们将不胜感激。

【问题讨论】:

    标签: json oauth axios zoom-sdk


    【解决方案1】:

    引发错误是因为您将数据作为发布请求的主体发送,而 Request Access Token Zoom API 期望将它们作为查询参数找到,您可能将其称为查询字符串。

    参考

    https://marketplace.zoom.us/docs/guides/auth/oauth#local-test

    Image of page from link to highlight the use of query parameters and content-type requirement for API call

    改变

    var options = {
      method: "POST",
      url: "https://zoom.us/oauth/token",
      body: JSON.stringify({
        grant_type: "authorization_code",
        code: process.env.AUTH_CODE,
      }),
      redirect_uri: "https://zoom.us",
    };
    

    var options = {
          method: "POST",
          url: "https://zoom.us/oauth/token",
          params: {
            grant_type: "authorization_code",
            code: process.env.AUTH_CODE,
            redirect_uri: "<must match redirect uri used during the app setup on zoom>"
          },
        };
    

    Content-Type 标头应设置为 application/x-www-form-urlencoded,因为这是缩放 API 本身的要求。

    顺便说一句,axios 要求您将请求的主体字段/对象命名为数据,并且也不需要 JSON.stringify() 方法,因为 axios 会为您做到这一点引擎盖下

    【讨论】:

      猜你喜欢
      • 2018-05-03
      • 1970-01-01
      • 2012-11-06
      • 2019-09-16
      • 1970-01-01
      • 2012-09-29
      • 2017-12-11
      • 1970-01-01
      • 2018-12-27
      相关资源
      最近更新 更多