【发布时间】:2015-06-14 13:46:38
【问题描述】:
我正在尝试将状态参数发送到 Oauth,然后在回调中捕获它们,但我无法使其工作。那么passportjs是否支持这样的功能呢?
我的想法是将 id 作为状态参数发送到 Oauth,然后根据状态参数中的 id 发送回我的应用程序的回调,我想做一个正确的重定向。
在我启用的 Twitter 策略中
passReqToCallback: true,
state: true
我的请求应该是这样的:
app.get('/auth/twitter/:gameId/:url',
function(req, res){
try {
var json = JSON.stringify({gameId: req.params.gameId, url: req.params.url});
var encodedValues = base64url(json);
console.log('encodedValues:'+encodedValues)
passport.authenticate('twitter', {state:encodedValues})
}catch (e){
console.log(e);
}
}
);
然后在回调上
app.get('/auth/twitter/callback', passport.authenticate('twitter', function(req, res, next) {
try{
//get the state params from the res uri/body
//decode the state params
//redirect depending on the state.gameId
}catch(e){
console.log('twitter exception:'+e);
}}));
我已经知道我可以将 id 保存在会话中,但我想知道是否有会话较少的方法可以通过从 url 传递此信息来做到这一点,因为它不敏感。
谢谢
【问题讨论】:
-
你知道怎么做吗?看起来 Twitter 支持 OAuth 1 但不支持 2 所以不支持 state 参数。
-
还没有。由于缺乏信息,我计划使用会话来存储参数。
标签: node.js oauth oauth-2.0 passport.js