Passport.js +防爆press.js着用户对原目的地后进行身份验证 [英] Passport.js + Express.js forward user to original destination after authenticating
问题描述
我有一个应用程序,是节点+防爆preSS +护照服务器和jQuery + Backbone.js的客户端上。客户利用哈希标签中的URL,但对于某些功能是很重要的,以中登录的用户。
I have an app that is Node + Express + Passport on the server and jQuery + Backbone.js on the client. The client makes use of hash tags in the URL, but for some functionality it's important for the user to be logged in.
我想应用程序是通过URL,例如访问 http://mydomain.com/app#cone/waffle/flavor/mint/toppings/sprinkles
这样:
I'd like the app to be accessible via URL, e.g. http://mydomain.com/app#cone/waffle/flavor/mint/toppings/sprinkles
such that:
- 如果用户已登录,他们到所请求的URL的情况下直接麻烦
- 如果用户尚未登录,他们到
/登录
,然后去请求的URL
- if user is already logged in, they go to the requested URL directly without hassles
- if user is not already logged in, they go to
/login
and then go to the requested URL
在此之后SO后,
<一href=\"http://stackoverflow.com/questions/9885711/custom-returnurl-on-node-js-passports-google-strategy\">Custom RETURNURL上的Node.js护照的谷歌战略,我有这样
Following this SO post, Custom returnUrl on Node.js Passport's Google strategy, I have it so that
- 如果他们已经登录,就直接去了网址,哈希代码和所有
- 如果他们没有被记录下来,这需要他们到登录页面,然后到请求的URL,但...
这似乎从登录后重定向原始URL去掉哈希参数。
有什么办法preserve哈希参数将其重定向到原来的目标时?
Is there any way to preserve the hash parameters when redirecting them to the original destination?
从这个帖子,从请求URL获取哈希参数我得到的想法哈希代码不可用的服务器,它是使用哈希标签的整点上。
From this post, Getting hash parameters from request url I get the idea that the hash tags aren't available on the server, which is the whole point of using hash tags.
所以我怀疑这是不可能的。也许缓存PARAMS本地不知何故并获取他们的重定向,说 [原创URL减去hastags] +#使用缓存-PARAMS
?
So I suspect it's not possible. Maybe cache the params locally somehow and retrieve them on redirect, say to [original URL minus hastags] + #use-cached-params
?
推荐答案
哈希参数是浏览器而已,他们不会去到服务器。你可以尽管使用这种技术重定向回来,哈希代码和所有:
Hash parameters are browser-only, they won't go to the server. You can use this technique though for redirecting back, hash-tags and all:
- GET /一些/页#与/散列
- 登录?然后渲染页面
- 没有登录?呈现了一些JavaScript上有一个页面,说'getHash.jade
- getHash.jade:拷贝完整的URL,然后重定向到/登录和放大器;重定向='+ originalURL
- GET /登录(现在你可以在服务器上保存的哈希值,并从那里)
这篇关于Passport.js +防爆press.js着用户对原目的地后进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!