我正在使用passport-facebook登录我的用户,但看起来回调没有正常工作。当我尝试登录时,它会在Chrome网络标签中显示一个待处理的请求:
http://localhost:3000/auth/facebook/callback?code= **** _ 46H1el1ysca5wloo8PX7iWxdVGGavNgiFOp4rKv63pH6b5IVcaWntTLF6u4kpnb2PYWShhdRb8jVPiknwd0_wvyFTvVTAWevwwfTE6zAPk10g9gX6qmlAIWwi3XKz3FCOEB8j_c_hF7nI4I3beD52TUI5jIrgWqWdubzDvpzlZsgve7-ThFZJO-hSFByyY4VKiw3UMw_keQxhDgOORKthe8Dh_tyhP8sjVJ8lxvhSQstP7IbaBqtwa0DgxCToVOQkUILphzThd6dVrFIFAaf0VbVYrgQdWoSSDKJWnh0CPLWEkB6I7aU63iRO6ew527XZ8BUgCDHONNSQ2b1jT -
一段时间后,请求失败,状态为500.这就是我的节点服务器显示的内容:
GET /auth/facebook 302 1.602 ms - 0
GET /auth/facebook/callback?code=***_EC2RZfeVmZPO26_GNC01khGONZ67hPUae2BMbaLnSAUWFDNYH9zAVuegm1EPJM3QOtgF821np0pAYGo0UeZgwEPb07R5p3UXtOi18vGy6I2QIYAOLbxpXPZ3Kbg6PKlQkuyI6upWB7vHnMHcSm6eybe0l5TjCkli9vmEXRM9Rmvv3uGu8n0fhSyLkzDqS8CDGsKBwdmW4wmNuL5pc-OaHHsVvguFlnZW4gvCvhhOJ3qle6p6dcIJa-1XAuRgKEukRXn8w7oxF_ueIHvO9cm6iGzvAkIOCfWIlY-wdm-ounTGH6EWhZuVUtRbWsq5kLxxuDPfRbKrhtDNeYWbuBV - - ms - -
GET /auth/facebook/callback?code=****_EC2RZfeVmZPO26_GNC01khGONZ67hPUae2BMbaLnSAUWFDNYH9zAVuegm1EPJM3QOtgF821np0pAYGo0UeZgwEPb07R5p3UXtOi18vGy6I2QIYAOLbxpXPZ3Kbg6PKlQkuyI6upWB7vHnMHcSm6eybe0l5TjCkli9vmEXRM9Rmvv3uGu8n0fhSyLkzDqS8CDGsKBwdmW4wmNuL5pc-OaHHsVvguFlnZW4gvCvhhOJ3qle6p6dcIJa-1XAuRgKEukRXn8w7oxF_ueIHvO9cm6iGzvAkIOCfWIlY-wdm-ounTGH6EWhZuVUtRbWsq5kLxxuDPfRbKrhtDNeYWbuBV FacebookTokenError: This authorization code has been used.
at Strategy.parseErrorResponse (C:\Users\alucardu\IdeaProjects\movieseat-2.0\node_modules\passport-facebook\lib\strategy.js:196:12)
500 172.152 ms - 1326
at Strategy.OAuth2Strategy._createOAuthError (C:\Users\alucardu\IdeaProjects\movieseat-2.0\node_modules\passport-facebook\node_modules\passport-oauth2\lib\strategy.js:367:16)
at C:\Users\alucardu\IdeaProjects\movieseat-2.0\node_modules\passport-facebook\node_modules\passport-oauth2\lib\strategy.js:166:45
at C:\Users\alucardu\IdeaProjects\movieseat-2.0\node_modules\passport-facebook\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:177:18
at passBackControl (C:\Users\alucardu\IdeaProjects\movieseat-2.0\node_modules\passport-facebook\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:123:9)
at IncomingMessage.<anonymous> (C:\Users\alucardu\IdeaProjects\movieseat-2.0\node_modules\passport-facebook\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:143:7)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:913:12)
at nextTickCallbackWith2Args (node.js:442:9)
错误说明:
FacebookTokenError:已使用此授权码。
我的refreshToken
也未定义,但我不知道重要的是多少。
这是我的facebook路线:
router.get('/facebook', passport.authenticate('facebook', {
scope: ['email']
}));
router.get('/facebook/callback', passport.authenticate('facebook', {
successRedirect: '/',
failureRedirect: '/'
}));
passport.use('facebook', new FacebookStrategy({
clientID: '****99027210110',
clientSecret: '****4a1b8908ca7e43dc9ca6878d192',
callbackURL: 'http://localhost:3000/auth/facebook/callback',
passReqToCallback: true,
enableProof: true,
profileFields: ['displayName', 'emails']
}, function(req, accessToken, refreshToken, profile, done){
var user = {};
user.email = profile.emails[0].value;
user.displayName = profile.displayName;
user.facebook = {};
user.facebook.id = profile.id;
user.facebook.token = accessToken;
done(null, user);
}));