2014-01-15 142 views
14

誰能幫我用什麼是錯與護照的oauth2消費者InternalOAuthError:無法獲得訪問令牌

鏈接GitHub 的oauth2提供商服務器下面的代碼後,我登錄與http://localhost:8082,並達到我的回調URL : http://localhost:8081/auth/provider/callback,它拋出一個錯誤

var express = require('express') 
    , passport = require('passport') 
    , util = require('util') 
    , TwitterStrategy = require('passport-twitter').Strategy; 

var TWITTER_CONSUMER_KEY = "--insert-twitter-consumer-key-here--"; 
var TWITTER_CONSUMER_SECRET = "--insert-twitter-consumer-secret-here--"; 

passport.serializeUser(function(user, done) { 
    done(null, user); 
}); 

passport.deserializeUser(function(obj, done) { 
    done(null, obj); 
}); 

passport.use(new TwitterStrategy({ 
    consumerKey: TWITTER_CONSUMER_KEY, 
    consumerSecret: TWITTER_CONSUMER_SECRET, 
    callbackURL: "http://127.0.0.1:3000/auth/twitter/callback" 
    }, 
    function(token, tokenSecret, profile, done) { 
    // asynchronous verification, for effect... 
    process.nextTick(function() { 

     return done(null, profile); 
    }); 
    } 
)); 


var app = express.createServer(); 

// configure Express 
app.configure(function() { 
    app.set('views', __dirname + '/views'); 
    app.set('view engine', 'ejs'); 
    app.use(express.logger()); 
    app.use(express.cookieParser()); 
    app.use(express.bodyParser()); 
    app.use(express.methodOverride()); 
    app.use(express.session({ secret: 'keyboard cat' })); 
    app.use(passport.initialize()); 
    app.use(passport.session()); 
    app.use(app.router); 
    app.use(express.static(__dirname + '/public')); 
}); 


app.get('/', function(req, res){ 
    res.render('index', { user: req.user }); 
}); 

app.get('/account', ensureAuthenticated, function(req, res){ 
    res.render('account', { user: req.user }); 
}); 

app.get('/login', function(req, res){ 
    res.render('login', { user: req.user }); 
}); 

app.get('/auth/twitter', 
    passport.authenticate('twitter'), 
    function(req, res){ 
    // The request will be redirected to Twitter for authentication, so this 
    // function will not be called. 
    }); 

app.get('/auth/twitter/callback', 
    passport.authenticate('twitter', { failureRedirect: '/login' }), 
    function(req, res) { 
    res.redirect('/'); 
    }); 

app.get('/logout', function(req, res){ 
    req.logout(); 
    res.redirect('/'); 
}); 

app.listen(3000); 

function ensureAuthenticated(req, res, next) { 
    if (req.isAuthenticated()) { return next(); } 
    res.redirect('/login') 
} 

InternalOAuthError: Failed to obtain access token

我怎樣才能解決這個問題?

+1

你有沒有想過這個? –

+0

這沒有意義。如何在沒有獲得「access_token」的情況下登錄成功?我認爲這個問題是不同的,一些信息在這裏丟失。 –

+0

也許它是序列化和反序列化funcs? –

回答

5

同樣在這裏我得到了同樣的問題。最後我發現一個解決方案與公司代理有關,你可以檢查出解決方法here

+1

我們與其他網站有點不同;這不是一個討論論壇,而是一個 問答網站,我們在那裏爲答案保留答案空間。請查看我們的 短[遊覽]。您能否請[編輯]更直接地解決 問題? – rrauenza