【问题标题】:OAuth2 using Curl/Node.js is not giving any response使用 Curl/Node.js 的 OAuth2 没有给出任何响应
【发布时间】:2017-10-24 13:46:16
【问题描述】:

我可以使用带有以下参数的邮递员成功创建访问令牌, 回调地址:https://www.getpostman.com/oauth2/callback 代币名称: 授权网址: 访问令牌网址: 客户编号: 客户秘密: 授予类型:客户端凭据。

但我无法通过 Curl 或 node.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);
});

我将邮递员详细信息映射到 node.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的脚本

【问题讨论】:

    标签: node.js curl oauth-2.0 access-token postman


    【解决方案1】:

    经过一番研究,我自己找到了通过使用请求的代码生成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方法获取访问令牌,

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-04
      • 1970-01-01
      • 2021-05-07
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      • 1970-01-01
      相关资源
      最近更新 更多