stefanbuck / sails-social-auth-example

Sails.js Social Auth example with Passport and MongoDB
243 stars 62 forks source link

use req.session in config/express.js ? #34

Closed waflessnet closed 8 years ago

waflessnet commented 8 years ago

Hi, how can use 'req.session' in the file passorpt, i want do dynamic

passport.use(new TwitterStrategy({ consumerKey: req.session.client_id, consumerSecret:req.session.client_secret, callbackURL: 'http://localhost:1337/auth/twitter/callback' }, verifyHandler));

Thanks!

stefanbuck commented 8 years ago

You can choose between the sails way http://sailsjs.org/documentation/concepts/configuration or using environment variables.

passport.use(new TwitterStrategy({
    consumerKey: process.env.TWITTER_KEY,
    consumerSecret: process.env.TWITTER_SECRET,
    callbackURL: 'http://localhost:1337/auth/twitter/callback'
}, verifyHandler));

Now, the magic happens when you run the application like this

TWITTER_KEY=123 TWITTER_SECRET=456 sails lift
waflessnet commented 8 years ago

Ok, but the idea is before login, select a parameter, then based on this select the appropriate tokens in the database. Is change tokens in time execute.

The parameters is selected before login, it´s param save in 'req.session'. by it want to use req.session Thanks !

stefanbuck commented 8 years ago

I'm not sure if this is possible and how you could do that. Your questions is how to plug-in a middleware at run-time. Ask the maintainer if and how this is possible. Good luck