使用Express获取Auth0的访问令牌 [英] Getting access token for Auth0 with Express

查看:0
本文介绍了使用Express获取Auth0的访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的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()
});

我收到"未授权错误:未找到授权令牌"。

我如何才能正确地执行此操作?

推荐答案

是否确实已在应用程序中启用CLIENT_Credentials授权类型? 转到应用程序/高级/授权类型并启用CLIENT_Credentials

See picture here

这篇关于使用Express获取Auth0的访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆