PassportJS - 动态设置状态以允许在回调时重定向
PassportJS - Dynamically set state to allow redirect on callback
所以我正在处理这里提供的信息,以添加Google在重定向到Google之前将重定向到用户所在的页面的功能。我目前正在使用最新版本的Express,PassportJS和Google oauth2。
例如,如果用户点击页面 http://example.com/privatecontent,它会自动重定向到 Google 要求登录,成功后它会返回到我的 Node App,只是它不知道最后一页是/privatecontent,而是重定向到索引。
如果我理解正确,我可以使用 state 参数让 Google 知道将状态参数发回,以便我可以读取它并重定向自己。
我基本上希望我的函数看起来像这样,但我无法访问 req.headers,或者只是不知道在 passport.authenticate 中有多诚实。
app.get("/auth/google", passport.authenticate("google", {
scope: ["https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email"],
state: base64url(JSON.stringify({
lastUrl: req.headers['referer']
}))
}), function(req, res) {});
创建自定义中间件
function myCustomGoogleAuthenticator(req, res, next){
passport.authenticate({
scope: ...
state: // now you have `req`
})(req, res, next);
//^ call the middleware returned by passport.authenticate
}
改为将其添加到您的路线中
app.get("/auth/google", myCustomGoogleAuthenticator, function(req, res) {});
相关文章:
- http/rxjs catch回调中的Angular 2重定向导致TypeError:无法读取属性'订阅'
- Iframe提交并将用户重定向回原始页面,但Iframe似乎仍然存在
- Node.js express应用程序无法从dropzone.js回调进行重定向
- JavaScript 重定向回引用页面
- 访问另一个网站后重定向回自己的网页
- 护照身份验证回调而不是重定向
- 重定向回 2 个页面并重新加载该页面
- 如何将节点.js回调定向到非匿名函数
- jQuery表单插件:如何正确处理从服务器发回的重定向请求
- 检查弹出窗口是否已重定向回 JavaScript 中的打开程序的域/端口/协议
- PassportJS - 动态设置状态以允许在回调时重定向
- 当响应 JSON 对象数据计数为零时,AJAX 成功回调函数重定向到错误回调
- Response.重定向不能在会话超时的页面回调中调用
- 我可以在chrome扩展中为oauth2回调设置什么重定向URL
- 如何在 expressjs 中重定向后进行回调
- OAuth.使用OAuth获取tweet时出现未定义错误.重定向方法的回调
- 无法在Ajax包装上的自定义成功回调内部重定向
- 如何通过谷歌策略处理来自dpd护照的回调/重定向
- 在Angular中,如何使用$location重定向.路径为$http.Post success回调
- 关闭Twitter Oauth登录弹出窗口,用回调重定向到parent