当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Want passport to store req.client instead of req.user for Bearer strategy

问题描述:

I am a implementing Oauth2 bearer strategy to authenticate clients using passport.js.

I use the passport-http-bearer package and implemented the following callback:

 passport.use(new BearerStrategy(

function (accessToken, done) {

Token.findOne({ token: accessToken }).populate('client').exec(function (err, token) {

if (err) {

return done(err);

}

if (!token) {

return done(null, false);

}

if (new Date() > token.expirationDate) {

Token.remove(accessToken, function (err) {

return done(err);

});

}

if (token.client) {

var info = { scope: token.client.scopes };

return done(null, token.client, info);

}

else {

return done(null, false);

}

});

}

));

Later on I want to read the client info - which gets placed under the req.user key by the passport done() callback.

Is there a way to get passport to store the returned client in req.client variable instead of req.user?

My goal is to authenticate users and clients with the same application, therefore I can't have conflicting keys in my request.

thanks

网友答案:

You can pass the user property while initialising passport.

app.use(passport.initialize({userProperty:'client')); 

passport will use this property to store info.

分享给朋友:
您可能感兴趣的文章:
随机阅读: