我们如何在node-oauth2-library模型中使`Request`可以访问

时间:2018-07-11 08:24:03

标签: node.js express oauth-2.0

我正在尝试使用node-oauth2-library实现Oauth2.0的client_credentials授予类型,这是我的oauth2Server代码段

const Model = require('./services/oauth2_service');

app.oauth = new oauthServer({
  model: Model,
  grants: ['client_credentials'],
  debug: true
});



app.all('/oauth/token', (req, resp) => {
    let request = new Request(req);
    let reponse = new Response(resp);
    return app.oauth.token(request, reponse);
});

这是我的模特:

    module.exports = {
        getAccessToken: (bearerToken, callback) => {
        access_token.findOne({
          accessToken: bearerToken
        }, callback);
      },
      getClient: async (clientId, clientSecret, callback) => {
          // console.log(new Request());
        let record = await client.findOne({clientId: clientId, clientSecret: clientSecret});
        if (record) {
                callback(null, record);
        } else {
                callback ("Client not found", null);
        }
      }
   }

现在我如何获得对诸如getClient之类的内部请求的访问。任何帮助,将不胜感激。谢谢。

0 个答案:

没有答案