我一直在努力让护照工作。我正在使用passport-github2,但是在尝试解决问题时,我也尝试了passport-facebook和twitter,但它们现在似乎都不起作用。
我有一个使用 facebook/twitter 登录的简单应用程序,现在它们不再工作了,所以这似乎与新版本的 Passport 有关。
这是我的 github.js 文件中的内容,可通过 url 访问api/auth/github
var express = require('express'),
router = express.Router(),
config = require('config'),
githubAuth = config.get('github'),
githubStrategy = require('passport-github2').Strategy,
flash = require('connect-flash'),
GITHUB_CLIENT_ID = githubAuth.githubClientID,
GITHUB_CLIENT_SECRET = githubAuth.githubClientSecret,
app = express();
//passport vars
var passport = require('passport'),
session = require('express-session'),
methodOverride = require('method-override'),
bodyParser = require("body-parser"),
cookieParser = require("cookie-parser");
passport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(function (obj, done) {
done(null, obj);
});
passport.use(new githubStrategy({
clientID: GITHUB_CLIENT_ID,
clientSecret: GITHUB_CLIENT_SECRET,
callbackURL: 'http://localhost:3000/api/auth/github/callback'
},
function (token, tokenSecret, profile, done) {
// asynchronous verification, for effect...
return done(null, profile);
}
));
app.use(cookieParser());
app.use(bodyParser());
app.use(methodOverride());
app.use(session({
secret: 'keyboard cat',
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash())
router.get('/', passport.authenticate('github', {
scope: ['user']
}));
router.get('/callback',
passport.authenticate('github', {
failureRedirect: '/',
successRedirect: '/'
}),
function (req, res) {
res.send('Hello World!!');
}
);
module.exports = router;
当我去http://localhost:3000/api/auth/github
github 时,让我进行身份验证,然后单击绿色按钮,该按钮将带我回到回调 url,然后一切都爆炸了,我看到了这条消息:
Error
at /Users/cynt005/Documents/Code/UXUIteamwebsite/node_modules/passport-github2/lib/strategy.js:96:19
at passBackControl (/Users/cynt005/Documents/Code/UXUIteamwebsite/node_modules/oauth/lib/oauth2.js:132:9)
at IncomingMessage.<anonymous> (/Users/cynt005/Documents/Code/UXUIteamwebsite/node_modules/oauth/lib/oauth2.js:157:7)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1059:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
安慰:
GET http://localhost:3000/api/auth/github/callback?code=60a130c5c54a6fc30266 500 (Internal Server Error)
我在网上搜索了所有内容,但找不到适合我的解决方案。github中有一个thread,但是官方还没有给出解决方案:
https://github.com/jaredhanson/passport-facebook/issues/100
任何帮助将不胜感激 !!