【问题标题】:Getting access token for Auth0 with Express使用 Express 获取 Auth0 的访问令牌
【发布时间】:2020-05-30 11:57:21
【问题描述】:

在我的 Express 应用程序中,我必须获取 Auth0 的访问令牌。在文档中,他们有一个带有请求的纯 Node JS 示例:

var request = require("request");

var options = { method: 'POST',
  url: 'https://XXX.eu.auth0.com/oauth/token',
  headers: { 'content-type': 'application/json' },
  body: '{"client_id":"XXX","client_secret":"XXX","audience":"http://localhost:3001/","grant_type":"client_credentials"}' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

但是当我尝试以另一种方式做同样的事情时:

app.post('/token', function(options, res) {
  return res.json()
});

我收到“UnauthorizedError:未找到授权令牌”。

我怎样才能正确地做到这一点?

【问题讨论】:

    标签: node.js express axios auth0


    【解决方案1】:

    您确定在您的应用中启用了 client_credentials 授权类型吗? 转到应用程序/高级/授权类型并启用 client_credentials

    See picture here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-13
      • 2019-11-08
      • 2018-01-13
      • 2017-12-29
      • 2019-07-20
      • 1970-01-01
      • 1970-01-01
      • 2019-02-01
      相关资源
      最近更新 更多