English 中文(简体)
关闭窗口,在登录后重定向到旧页面 [客户侧插图]
原标题:closing a window, Redirecting to old page after a login [client side prog]

我正与Youtube Api合作, 使用Oauth 2. 0 用于客户方授权。

< a href=>https:// developmenters.google.com/youtube/2.0/ Developingers_guide_protocol_oauuth2#OAuth2_Client_Side_Web_Applications_Flow> rel=“无跟踪”https://developers.google.com/youtube/2.0/ Developers_guide_protocol_oauth2#OAuth2_Client_Side_Web_Applications_Flow

当点击登录以google oauth 2. 0 打开一个新授权窗口, 并被重定向时, 它打开新窗口( 用于授权) 中重定向的 Url, 登录成功或失败后如何操作, 我关闭登录窗口, 然后用符号和结果返回原始网站 。

如果你要建议一个会话变量来实施这个, 我认为用客户方的方案拟订方法, 这是不可能的。

我需要一种类似的登录/授权方法, 和这里一样:

http://gdata-samples.googlecode.com/svn/trunk/gdata/youtube_upload_cors.html I tried to decipher the code, but it dint work out.

我更希望采取客户方办法,因为我计划的工作完全是客户驱动的(JS)

谢谢 谢谢

问题回答

最好的办法可能是HTML5后发邮件。

然而,在我的《OAuth 2.0 书中,我有一个使用标准 JavaScript 和 window.opener 的可行方法。

我有一个名为 oath2 callback.html 的页面。 此页面是您的 < code> redirect_ uri 。 它在 URL 中的 hash 碎片中解析访问符号, 在 < code> window. opener 中调用 JS 函数来设置访问符号, 然后关闭它 :

<html>
<body>
<script type="text/javascript">
var oauthParams = {};

// parse the query string
// from http://oauthssodemo.appspot.com/step/2
var params = {}, queryString = location.hash.substring(1),
    regex = /([^&=]+)=([^&]*)/g, m;
while (m = regex.exec(queryString)) {
  oauthParams[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}

window.opener.setOauthParams(oauthParams);
window.opener.callApi();
window.close();
</script>
</body>
</html>

父页(通过在弹出时打开 OAUT 流来启动整个进程)有一个简单的 JavaScript 函数,叫做 < code> setOauthParams ,该函数接受参数并将其存储到一个全球变量中 :

function setOauthParams(oauthParamsPassed) {
  this.oauthParams = oauthParamsPassed;
}   

我有其他代码 启动OAUT流 并使用jQuery 调用 API(我的情况中的谷歌联系人), 但它听起来不像你需要。





相关问题
C# Networking API s [closed]

Lately I ve been looking for a good networking API i could possibly use and/or reference some of the code within, but i have mere luck searching for some on Google/Bing. Hopefully somebody here has ...

getting XML from other domain using ASP.NET

I m fairly new to ASP.NET. And I was wondering how I could go about getting xml from a site (Kuler s API in this case), and then post the result using AJAX? So what I want here, is to be able to do a ...

Most appropriate API for URL shortening service

I ve just finished an online service for shortening URLs (in php5 with Zend Framework); you can enter an URL and you get an short URL (like tinyurl and such sites). I m thinking about the API for ...

UML Diagram to Model API

I need to create a diagram to document a RESTFul API that build, which UML diagram should I use? Thanks in advance,

How best to expose Rails methods via an API?

Let s say I have a model foo, and my model has a publish! method that changes a few properties on that model and potentially a few others too. Now, the Rails way suggests that I expose my model over ...

简讯

我是否可以使用某些软件来建立简便的航天国家服务器,最好是在 Java? 所有我都希望我的航天国家服务机在任何要求中都用同样的IP地址来回答。

About paypal express checkout api

In this picture,there are 3 main steps:SetExpressCheckout,GetExpressCheckoutDetails and DoExpressCheckoutDetails,I m now sure SetExpressCheckout is to be called by myself,what about ...

热门标签