问题描述
我已经在 Twitter 和 Facebook 上完成了 OAuth 身份验证.目前,对于这些站点中的每一个,我的服务器将用户重定向到指定的 URL(例如,http://api.twitter/oauth/authorize 与 Twitter),然后通过回调 url 接收身份验证参数.
I have done OAuth authentication with Twitter and Facebook. Currently, with each of these site, my server redirect user to a specified URL (for example, http://api.twitter/oauth/authorize with Twitter), then receive authentication parameters by callback url.
但是通过这种方式,用户会被重定向出我的页面(到 Facebook 或 Twitter),并且只有在输入正确的用户名后才返回密码.这就像 http://techcrunch 在用户尝试发推文时所做的那样.
But by that way, the users get redirected out of my page (to Facebook or Twitter), and only returns after input correct username & password. It's like the way http://techcrunch do it when a user try to tweet a post.
我记得在某些站点中,我看到我们不能通过将用户重定向出去来连接,而是打开一个弹出窗口让用户输入凭据.认证完成后,弹窗关闭,主页面刷新新内容.
I remember that in some site, I have seen that we can connect not by redirect user out, but open a popup window for user to input credentials instead. After authentication is completde, the pop-up closed, the main page refresh with new content.
这可能是使用 javascript 的一项非常简单的任务,但我仍然无法弄清楚.我可以在弹出窗口中打开身份验证 URL,但是如何获取结果 &更新主页?
This could be a very simple task with javascript, but I still can't figure it out. I can open authentication URL in a pop-up window, but how to get the result & update the main page?
推荐答案
假设您使用 window.open()
在弹出窗口中打开身份验证 url,您可以通过使用访问父窗口:
Assuming you're opening authentication url in a pop-up using window.open()
, you can access parent window by using:
window.opener
并重新加载父窗口(从弹出窗口)使用:
and to reload parent window (from a pop-up) use:
window.opener.location.reload();
此代码应在您设置为 oauth 授权的成功回调 url 的 url 上提供.
This code should be served on url that you've set up as success callback url of oauth authorization.
一般来说,流程应该是:
In general, the flow should be:
打开一个带有授权页面的弹出窗口(例如在 twitter 上)成功授权后,twitter 将用户重定向到您提供的网址(它会在同一个弹出窗口中打开)打开器窗口被重新加载(通过window.opener.location.reload()
)关闭弹出窗口本身(使用 javascript 是你想要的)
这篇关于如何通过打开新窗口而不是从当前页面重定向用户来执行 OAuth 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论