【问题标题】:Exchange authorization_code for access_token and id_token not working using Auth0access_token 和 id_token 的交换授权码无法使用 Auth0
【发布时间】:2017-03-24 10:27:46
【问题描述】:

我正在使用 Auth0 短信无密码登录,我可以正确登录,并且我被正确重定向到我指定的回调 url:http://localhost:8000/authenticated?code=AUTHORIZATION_CODE。我一直在关注this 教程,但是当我进入第 4 步和第 5 步以交换 access_token 和 id_token 的授权码时,我收到了这条错误消息:{"error":"access_denied","error_description":"Unauthorized"}

这就是我通过 POST 将代码发送到 Auth0 服务器的方式:

var code = request.query.code;
var url = `https://${process.env.AUTH0_CLIENT_DOMAIN}/oauth/token?client_id=${process.env.AUTH0_CLIENT_ID}&redirect_uri=http://localhost:8000/authenticated&client_secret=${process.env.AUTH0_CLIENT_SECRET}&code=${code}&grant_type=authorization_code`;

Wreck.post(url, (err, res, payload) => {
  console.log(payload.toString());
});

我的查询字符串中是否缺少某些内容?或者在发送此帖子请求之前我需要做些什么?

【问题讨论】:

    标签: oauth-2.0 auth0


    【解决方案1】:

    我的问题在 auth0 存储库的一个问题中得到了解答:https://github.com/auth0/auth0.js/issues/234

    但我已经在这里重新发布了答案:

    发布有效负载,而不是将其作为查询字符串中的参数发送:

    var code = request.query.code;
    var url = `https://${process.env.AUTH0_CLIENT_DOMAIN}/oauth/token`;
    var body = { 
      client_id:process.env.AUTH0_CLIENT_ID,
      redirect_uri:'http://localhost:8000/authenticated',
      client_secret:process.env.AUTH0_CLIENT_SECRET,
      code:code,
      grant_type:'authorization_code'
    };
    
    Wreck.post(url, {payload:body}, (err, res, payload) => {
        console.log(payload.toString());
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-24
      • 2015-10-08
      • 2017-04-04
      • 1970-01-01
      • 2017-05-19
      • 1970-01-01
      • 2018-10-25
      相关资源
      最近更新 更多