【发布时间】:2018-08-25 02:08:11
【问题描述】:
const TwitterStrategy = require('passport-twitter').Strategy;
module.exports = (passport, User) => {
passport.use(new TwitterStrategy({
consumerKey: 'paLCHei1bz8uG5mzNK3ZmvWy7',
consumerSecret: 'djwTrPntW6T2hm3EJ6eIvUrqObMSymgKn6B1foMQyNeypjtbIK',
callbackURL: 'http://localhost:3000/auth/twitter/callback',
passReqToCallback: true
}, (req, accessToken, tokenSecret, profile, done) => {
User.findOne({ 'twitter.id': profile.id }, (err, x) => {
if (x) return done(null, x);
var user = {
image: profile._json.profile_image_url,
displayName: profile.displayName,
email: profile.emails[0].value,
twitter: {
id: profile.id,
email: profile.emails[0].value
}
};
User.create(user, (err, x) => done(null, x));
});
}));
};
【问题讨论】:
-
欢迎来到 Stack Overflow!请阅读How to Ask 页面并更新您的问题。
标签: email twitter oauth passport.js