使用Express获取Auth0的访问令牌

时间:2020-02-14 16:49:26

标签: node.js express axios auth0

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

Main()

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

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);
});

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

我该怎么做?

1 个答案:

答案 0 :(得分:0)

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

See picture here