3

I am trying to authenticate the yammer user using Passport.

It can get through yammer authentication page and I can click to allow access but the function never gets call. ( As you might see in my code, I just want to print all accessToken, profile but it never prints them out. )

Please help me I might not do it properly.

var express = require("express");
var app = express();
var passport = require("passport");
var YammerStrategy = require("passport-yammer").Strategy
passport.use(new YammerStrategy({
  clientID: "",
  clientSecret: "",
  callbackURL: "/"
  },
  function(accessToken, refreshToken, profile, done){
    process.nextTick(function (){
      console.log("strategy");
      console.log(profile);
      console.log(accessToken);
      console.log(refreshToken);
    });

  }
));

app.get('/login', passport.authenticate('yammer'));
app.listen(3000);
console.log('Listening on port 3000');
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
A-letubby
  • 8,474
  • 8
  • 38
  • 48

1 Answers1

3

it happens because you never calling passport done callback, just call it

passport.use(new YammerStrategy({
  clientID: "",
  clientSecret: "",
  callbackURL: "/"
  },
  function(accessToken, refreshToken, profile, done){
    console.log("strategy");
    console.log(profile);
    console.log(accessToken);
    console.log(refreshToken);

    done(null, profile);
  }
));

and because you don't add your passport middleware:

app.configure(function() {
  app.use(express.static('public'));
  app.use(express.cookieParser());
  app.use(express.bodyParser());
  app.use(express.session({ secret: 'keyboard cat' }));
  app.use(passport.initialize());
  app.use(passport.session());
  app.use(app.router);
});
app.get('/login', passport.authenticate('yammer'));
app.listen(3000);
console.log('Listening on port 3000');

Read documentation:

krasu
  • 2,037
  • 23
  • 22
  • @A-letubby, check updated answer and read documentation by this link http://passportjs.org/guide/configure/ – krasu Oct 26 '13 at 23:46
  • ok, it works now. It's worthwhile to see the example of passport-yammer, too. https://github.com/jaredhanson/passport-yammer/blob/master/examples/login/app.js One more thing, I still don't understand what "done(null,profile)" for? in the example, they do "return done(null,profile)" but your code does not. – A-letubby Oct 28 '13 at 14:33
  • 1
    `return` just used to finish parent function execution. `done` function let passport know if user was authenticated or error appear during authentication. It is error first callback, so error comes as first argument and user data comes as second one. In my example you returning `null` as error and `profile` as user data, check the documentation http://passportjs.org/guide/configure/, especially Verify Callback section – krasu Oct 28 '13 at 14:59