oauth2 nodjs:无效的客户端:无法检索客户端凭据

时间:2018-06-24 04:57:27

标签: node.js express oauth-2.0 oauth2-server

我正在尝试使用oauth2服务器在Express js中实现oauth2

https://oauth2-server.readthedocs.io/en/latest/

 const oauth = new OAuth2Server({
  model: require('../../models/model')
});

    const oauthRequest = function oauthRequest(req,res){

        console.log(req.body);
        const request = new Request(req);
        const response = new Response(res);

        oauth
        .token(request,response)
        .then(function(token) {
          // Todo: remove unnecessary values in response
          return res.json(token)
        }).catch(function(err){
          return res.status( 500).json(err)
        })
    }

问题是我收到错误响应

{
    "statusCode": 400,
    "status": 400,
    "code": 400,
    "message": "Invalid client: cannot retrieve client credentials",
    "name": "invalid_client"
}

这里是模型定义

const getClient = function getClient(clientId,clientSecret,callback){
    return callback({
        id:'1356',
        redirectUris:'http://localhost:3005/auth/jjhkj',
        grants:['email'],
        accessTokenLifetime:2,
        refreshTokenLifetime:20,
        client:{
            name:'test'
        }
    })
}


module.exports = {
    getClient
}

登录req.body后,我可以正确接收请求

{ clientId: '13488',
  clientSecret: '15667',
  grant_type: 'authorization_code',
  code: '898989' }

我想发布另一个问题并将其重定向到回调URL,这是怎么可能的?

0 个答案:

没有答案