我必須在這裏俯瞰的東西。我正在使用passportjs的Facebook策略來驗證用戶身份。這是與2個請求/ [路由執行]完成:passportjs臉譜通過要求回電
//one to initiate the the auth:
init: function (req, res, next) {
passport.authenticate('facebook', {
callbackURL: URL + '/facebook/callback',
state: req.body //attempting to put some state
})(req, res, next)
}
//one callback
callback: function (req, res, next) {
passport.authenticate('facebook', {
callbackURL: URL + '/facebook/callback'
},
function (err, profile, accessToken, refreshToken) {
if (err) return next(err)
res.send(passedReqBody)
})(req, res, next)
}
//the verify callback doesn't do much.
//Application logic is done in route callback handlers
passport.use(new FacebookStrategy({
clientID: config.facebook.id,
clientSecret: config.facebook.secret
},
//When setting passReqToCallback to true, it is set as the first argument
//to the verify callback. As in:
//function (req, accessToken, refreshToken, params, profile, done) {
//But this is the 'callback' request object. I want the 'init' request object.
function (accessToken, refreshToken, params, profile, done) {
//params.state is undefined
return done(null, profile, accessToken, refreshToken);
}));
我的問題是,我想第一個函數的POST請求體在回調路由處理被曝光。
有到OAuth2Strategy構造「passReqToCallback」,它發送的最新要求回驗證回調,這是沒有用的,我(我想第一request.body)
接下來的事情提供一個選項,看着一個合理的路徑,是使用了「狀態」選項,如在https://github.com/jaredhanson/passport-oauth/blob/master/lib/passport-oauth/strategies/oauth2.js#L169
但這些值不可對getOAuthAccessToken回調https://github.com/jaredhanson/passport-oauth/blob/master/lib/passport-oauth/strategies/oauth2.js#L124
我現在的選擇是添加OAuth2Strategy內一個額外的變量.prototype.authenticate ()函數,該函數在第一個函數中被設置,並且被傳回回調函數,但我無法想象這是要走的路。
你的生活救星:)) –