Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- InternalOAuthError: Failed to obtain request token
- at Strategy.OAuthStrategy._createOAuthError (D:node_tutorialsoauthnode_modulespassport-oauth1libstrategy.js:396:17)
- at D:node_tutorialsoauthnode_modulespassport-oauth1libstrategy.js:244:41
- at D:node_tutorialsoauthnode_modulesoauthliboauth.js:543:17
- at ClientRequest.<anonymous> (D:node_tutorialsoauthnode_modulesoauthliboauth.js:421:9)
- at emitOne (events.js:96:13)
- at ClientRequest.emit (events.js:188:7)
- at TLSSocket.socketErrorListener (_http_client.js:308:9)
- at emitOne (events.js:96:13)
- at TLSSocket.emit (events.js:188:7)
- at emitErrorNT (net.js:1271:8)
- at _combinedTickCallback (internal/process/next_tick.js:74:11)
- at process._tickCallback (internal/process/next_tick.js:98:9)
- module.exports = {
- 'twitterAuth' : {
- 'consumerKey' : 'consumerKey',
- 'consumerSecret' : 'consumerSecret',
- 'callbackURL' : 'http://127.0.0.1:8080/auth/twitter/callback'
- }
- };
- module.exports = function(app, passport) {
- // route for home page
- app.get('/', function(req, res) {
- res.render('index.ejs'); // load the index.ejs file
- });
- // route for login form
- // route for processing the login form
- // route for signup form
- // route for processing the signup form
- // route for showing the profile page
- app.get('/profile', isLoggedIn, function(req, res) {
- res.render('profile.ejs', {
- user : req.user // get the user out of session and pass to template
- });
- });
- // route for logging out
- app.get('/logout', function(req, res) {
- req.logout();
- res.redirect('/');
- });
- // facebook routes
- // =====================================
- // TWITTER ROUTES =====================
- // =====================================
- // route for twitter authentication and login
- app.get('/auth/twitter', passport.authenticate('twitter'));
- // handle the callback after twitter has authenticated the user
- app.get('/auth/twitter/callback',
- passport.authenticate('twitter', {
- successRedirect : '/profile',
- failureRedirect : '/'
- }));
- };
- // route middleware to make sure a user is logged in
- function isLoggedIn(req, res, next) {
- // if user is authenticated in the session, carry on
- if (req.isAuthenticated())
- return next();
- // if they aren't redirect them to the home page
- res.redirect('/');
- }
- // load all the things we need
- var LocalStrategy = require('passport-local').Strategy;
- var FacebookStrategy = require('passport-facebook').Strategy;
- var TwitterStrategy = require('passport-twitter').Strategy;
- // load up the user model
- var User = require('../app/models/user');
- // load the auth variables
- var configAuth = require('./auth');
- module.exports = function(passport) {
- // used to serialize the user for the session
- passport.serializeUser(function(user, done) {
- done(null, user.id);
- });
- // used to deserialize the user
- passport.deserializeUser(function(id, done) {
- User.findById(id, function(err, user) {
- done(err, user);
- });
- });
- // code for login (use('local-login', new LocalStategy))
- // code for signup (use('local-signup', new LocalStategy))
- // code for facebook (use('facebook', new FacebookStrategy))
- // =========================================================================
- // TWITTER =================================================================
- // =========================================================================
- passport.use(new TwitterStrategy({
- consumerKey : configAuth.twitterAuth.consumerKey,
- consumerSecret : configAuth.twitterAuth.consumerSecret,
- callbackURL : configAuth.twitterAuth.callbackURL
- },
- function(token, tokenSecret, profile, done) {
- // make the code asynchronous
- // User.findOne won't fire until we have all our data back from Twitter
- process.nextTick(function() {
- User.findOne({ 'twitter.id' : profile.id }, function(err, user) {
- // if there is an error, stop everything and return that
- // ie an error connecting to the database
- if (err)
- return done(err);
- // if the user is found then log them in
- if (user) {
- return done(null, user); // user found, return that user
- } else {
- // if there is no user, create them
- var newUser = new User();
- // set all of the user data that we need
- newUser.twitter.id = profile.id;
- newUser.twitter.token = token;
- newUser.twitter.username = profile.username;
- newUser.twitter.displayName = profile.displayName;
- // save our user into the database
- newUser.save(function(err) {
- if (err)
- throw err;
- return done(null, newUser);
- });
- }
- });
- });
- }));
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement