Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get request object in Passport strategy callback

So here is my configuration for passport-facebook strategy:

    passport.use(new FacebookStrategy({         clientID: ".....",         clientSecret: ".....",         callbackURL: "http://localhost:1337/register/facebook/callback",     },     facebookVerificationHandler     )); 

And here is facebookVerificationHandler:

var facebookVerificationHandler = function (accessToken, refreshToken, profile, done) {      process.nextTick(function () {             .......     });     }; 

Is there a way to access to the request object in facebookVerificationHandler?

Users are registered to my site with a LocalStrategy but then they will be able to add their social accounts and associate those account with their local accounts. When the callback above is called, the user who is currently logged in is already available in req.user so I need to access req to associate the user with the facebook account.

Is this the correct way to implement it or should I consider another way of doing it?

Thanks.

like image 730
Élodie Petit Avatar asked Dec 02 '13 23:12

Élodie Petit


People also ask

What does the done function in passport strategy verify callback function do?

This is possible with the help of done() function. It is an internal passport js function that takes care of supplying user credentials after user is authenticated successfully. This function attaches the email id to the request object so that it is available on the callback url as "req.

What are strategies in Passportjs?

Strategies are responsible for authenticating requests, which they accomplish by implementing an authentication mechanism. Authentication mechanisms define how to encode a credential, such as a password or an assertion from an identity provider (IdP), in a request.

What does passport authenticate () do?

In this route, passport. authenticate() is middleware which will authenticate the request. By default, when authentication succeeds, the req. user property is set to the authenticated user, a login session is established, and the next function in the stack is called.

What is done in passport Nodejs?

Passport is a popular, modular authentication middleware for Node. js applications. With it, authentication can be easily integrated into any Node- and Express-based app. The Passport library provides more than 500 authentication mechanisms, including OAuth, JWT, and simple username and password based authentication.


1 Answers

There's a passReqToCallback option, see the bottom of this page for details: http://passportjs.org/guide/authorize/

like image 88
Jared Hanson Avatar answered Oct 01 '22 06:10

Jared Hanson