Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. InternalOAuthError: Failed to obtain request token
  2. at Strategy.OAuthStrategy._createOAuthError (D:node_tutorialsoauthnode_modulespassport-oauth1libstrategy.js:396:17)
  3. at D:node_tutorialsoauthnode_modulespassport-oauth1libstrategy.js:244:41
  4. at D:node_tutorialsoauthnode_modulesoauthliboauth.js:543:17
  5. at ClientRequest.<anonymous> (D:node_tutorialsoauthnode_modulesoauthliboauth.js:421:9)
  6. at emitOne (events.js:96:13)
  7. at ClientRequest.emit (events.js:188:7)
  8. at TLSSocket.socketErrorListener (_http_client.js:308:9)
  9. at emitOne (events.js:96:13)
  10. at TLSSocket.emit (events.js:188:7)
  11. at emitErrorNT (net.js:1271:8)
  12. at _combinedTickCallback (internal/process/next_tick.js:74:11)
  13. at process._tickCallback (internal/process/next_tick.js:98:9)
  14.  
  15. module.exports = {
  16.  
  17.  
  18.  
  19. 'twitterAuth' : {
  20. 'consumerKey' : 'consumerKey',
  21. 'consumerSecret' : 'consumerSecret',
  22. 'callbackURL' : 'http://127.0.0.1:8080/auth/twitter/callback'
  23. }
  24.  
  25.  
  26. };
  27.  
  28. module.exports = function(app, passport) {
  29.  
  30. // route for home page
  31. app.get('/', function(req, res) {
  32. res.render('index.ejs'); // load the index.ejs file
  33. });
  34.  
  35. // route for login form
  36. // route for processing the login form
  37. // route for signup form
  38. // route for processing the signup form
  39.  
  40. // route for showing the profile page
  41. app.get('/profile', isLoggedIn, function(req, res) {
  42. res.render('profile.ejs', {
  43. user : req.user // get the user out of session and pass to template
  44. });
  45. });
  46.  
  47. // route for logging out
  48. app.get('/logout', function(req, res) {
  49. req.logout();
  50. res.redirect('/');
  51. });
  52.  
  53. // facebook routes
  54.  
  55. // =====================================
  56. // TWITTER ROUTES =====================
  57. // =====================================
  58. // route for twitter authentication and login
  59. app.get('/auth/twitter', passport.authenticate('twitter'));
  60.  
  61. // handle the callback after twitter has authenticated the user
  62. app.get('/auth/twitter/callback',
  63. passport.authenticate('twitter', {
  64. successRedirect : '/profile',
  65. failureRedirect : '/'
  66. }));
  67.  
  68. };
  69.  
  70. // route middleware to make sure a user is logged in
  71. function isLoggedIn(req, res, next) {
  72.  
  73. // if user is authenticated in the session, carry on
  74. if (req.isAuthenticated())
  75. return next();
  76.  
  77. // if they aren't redirect them to the home page
  78. res.redirect('/');
  79. }
  80.  
  81. // load all the things we need
  82. var LocalStrategy = require('passport-local').Strategy;
  83. var FacebookStrategy = require('passport-facebook').Strategy;
  84. var TwitterStrategy = require('passport-twitter').Strategy;
  85.  
  86. // load up the user model
  87. var User = require('../app/models/user');
  88.  
  89. // load the auth variables
  90. var configAuth = require('./auth');
  91.  
  92. module.exports = function(passport) {
  93.  
  94. // used to serialize the user for the session
  95. passport.serializeUser(function(user, done) {
  96. done(null, user.id);
  97. });
  98.  
  99. // used to deserialize the user
  100. passport.deserializeUser(function(id, done) {
  101. User.findById(id, function(err, user) {
  102. done(err, user);
  103. });
  104. });
  105.  
  106. // code for login (use('local-login', new LocalStategy))
  107. // code for signup (use('local-signup', new LocalStategy))
  108. // code for facebook (use('facebook', new FacebookStrategy))
  109.  
  110. // =========================================================================
  111. // TWITTER =================================================================
  112. // =========================================================================
  113. passport.use(new TwitterStrategy({
  114.  
  115. consumerKey : configAuth.twitterAuth.consumerKey,
  116. consumerSecret : configAuth.twitterAuth.consumerSecret,
  117. callbackURL : configAuth.twitterAuth.callbackURL
  118.  
  119. },
  120. function(token, tokenSecret, profile, done) {
  121.  
  122. // make the code asynchronous
  123. // User.findOne won't fire until we have all our data back from Twitter
  124. process.nextTick(function() {
  125.  
  126. User.findOne({ 'twitter.id' : profile.id }, function(err, user) {
  127.  
  128. // if there is an error, stop everything and return that
  129. // ie an error connecting to the database
  130. if (err)
  131. return done(err);
  132.  
  133. // if the user is found then log them in
  134. if (user) {
  135. return done(null, user); // user found, return that user
  136. } else {
  137. // if there is no user, create them
  138. var newUser = new User();
  139.  
  140. // set all of the user data that we need
  141. newUser.twitter.id = profile.id;
  142. newUser.twitter.token = token;
  143. newUser.twitter.username = profile.username;
  144. newUser.twitter.displayName = profile.displayName;
  145.  
  146. // save our user into the database
  147. newUser.save(function(err) {
  148. if (err)
  149. throw err;
  150. return done(null, newUser);
  151. });
  152. }
  153. });
  154.  
  155. });
  156.  
  157. }));
  158.  
  159. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement