-
-
Notifications
You must be signed in to change notification settings - Fork 141
Open
Description
I had implemented passport-http-bearer for authentication and upon token expiry i need to send token expired message from my rest api.For that I throw a message from BearerStrategy .But from the library it throws only 'Unauthorized' message.
`passport.use(new BearerStrategy(
function(accessToken, done) {
AccessToken.findOne({where:{token:accessToken}}).then((token) => {
if (!token) {
return done(null, false);
}
if( Math.round((Date.now()-token.created_at)/1000) > config.expireTime ) {
AccessToken.destroy({where:{token: accessToken}}).catch(err =>{console.log(err);return done(err);});
return done(null, false, { message: 'Token expired' });
}
User.findById(token.user_id).then((user)=>{
if (!user) {
return done(null, false, { message: 'Unknown user' });
}
var info = { scope: '*' };
done(null, user, info);
}).catch(err => {console.log(err);return done(err); })
}).catch(err=>{console.log(err);return done(err);});`
And the api route is
app.get(version+'/grids',passport.authenticate('bearer', { session: false }),gridsController.list);
How to get the token expired message instead of 'Unauthorized' message
Metadata
Metadata
Assignees
Labels
No labels