Closed xellDart closed 5 years ago
Please be so kind and edit your description to a readable state first.
Please be so kind and edit your description to a readable state first.
Im sorry, I already up this
@xperiafan13-rom You don't get it there. You set it there for the next middlewares in the chain. Take the subject and pass it to your db adapter to find matching user.
Like:
(req, userinfo, done) => {
const user = await Users.findOne(userinfo.sub);
if(!user) return done(new Error('user not found in db!'));
return done(null, user);
}
Calling done
with error will call strategy.fail
and calling done with (null, someObject, someMoreInfo)
will call strategy.success
and set user.
You need to consult passport docs on how this works, but this strategy implements it here
But i need to load req.user on every request, in other strategies like twitter or google (and local) I use this:
if (req.user) {
let token = await Services.redis.setSocketToken(req.user);
return done(null, getUser(req.user, token));
} esle .... other logic
But withi this lib I cant get this param I already add passReqToCallback option to true (Association in Verify Callback)
That is not a issue of this library.
Read passport js docs. Especially the part with serialize
and deserialize
user.
I already have this
assport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(function (uid, done) {
done(null, uid);
});
and
let sessionMiddleware = session({
store: new redisStore({host: config.redis.host, port: config.redis.port}),
secret: config.session.key
});
If you could set up repo with a reproducible example, I might help you.
I'm reading http://www.passportjs.org/docs/authorize, i checked the underlying twitter strategy and there's nothing this library's strategy isn't doing that twitter would be.
You need to correctly handle building the profile from the tokenset or userinfo response as step one and then adding passport.authorize
call the same way you have probably have it for twitter or google.
You currently apply passport.authenticate
instead.
Hi, I use lasted version with nodeJS 12.0
Here is my code:
Endpoints:
Strategy:
Config:
I need get req.user on verify function, how i can get this param?