使用 Curl/Node 的 OAuth2.js 没有给出任何响应



我能够使用以下参数使用邮递员成功创建访问令牌,回调网址:https://www.getpostman.com/oauth2/callback令牌名称:身份验证网址:访问令牌网址:客户端 ID:客户端密码:授权类型:客户端凭据。

但是我无法通过 Curl 或节点获取访问令牌.js如下所示,

var request = require("request");
var options = { method: 'POST',
  url: '',
  headers: { 'content-type': 'application/json' },
  body: '{"client_id":"","client_secret":"","audience":","grant_type":"client_credentials"}' };
request(options, function (error, response, body) {
  if (error) console.log(error);
  //console.log(response);
  console.log(body);
});

我将我的邮递员详细信息映射到节点.js脚本的地方,

Auth URL: url
Access Token URL: audience
Client Id: client_id
Client Secret: client_secret
Grant Type: grant_type

但我没有任何回应。我可以知道我哪里出错了吗?或者我们是否有任何其他机制来获取 OAuth2 访问令牌?

我只是按照 https://manage.auth0.com/#/apis/590983763e3ae44a0dd1a219/test 的剧本

经过一些研究,我自己找到了使用请求通过代码生成 OAuth2 令牌的解决方案,我按 Postman 值映射到request_options中,如下所示:

const options = {
  url: access_token_url,
  method: 'POST',
  auth: {
    user: client_id,
    pass: client_secret,
  },
  form: {
    grant_type: grant_type,
  },
};

并使用请求方法通过以下方式获取访问令牌,

request(options, (error, response, body) => {
      if (error) return reject(error);
      return resolve(body);
    });

这有助于我在脚本中生成 OAuth2 访问令牌并修复了我的需求。

最新更新