2013-10-25 66 views
2

我正在嘗試使用Passport對yammer用戶進行身份驗證。Nodejs中的PassportJS從不調用回調函數

它可以通過yammer認證頁面,我可以點擊以允許訪問,但函數永遠不會調用。 (正如你可能在我的代碼中看到的,我只是想打印所有accessToken,配置文件,但它絕不會將它們打印出來。)

請幫助我我可能做得不對。

 
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'); 

回答

2

它發生,因爲你永遠不叫護照done回調,只是把它

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); 
    } 
)); 

因爲你不加你的護照中間件:

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

+0

我嘗試過但仍然一樣。該函數永遠不會調用。 –

+0

這樣做的用途是什麼? –

+0

@ A-letubby,檢查更新的答案,並閱讀文檔通過此鏈接http://passportjs.org/guide/configure/ – krasu