如何一次登录不同域中的多个应用程序? [英] How can I login to multiple applications in different domains once?

查看:72
本文介绍了如何一次登录不同域中的多个应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有2个应用,一个在abc.com中,另一个在xyz.com中.

For example I have 2 apps, one is in abc.com, and another one is in xyz.com.

现在我要做的是,如果一个用户登录了abc.com,那么他也将自动登录xyz.com.意味着在他登录abc.com之后,只需在浏览器的新标签页中打开xyz.com,就会显示他已经登录.

Now what I want to do is, if one user logged in abc.com, then he will be also logged in xyz.com automatically. Means after he logged in abc.com, and just open xyz.com in a new tab of browser, he will be showed that he has already logged in.

msn.comhotmail.com相同,如果您登录msn.com,然后打开hotmail.com,则可以看到您已经登录.

It's same as msn.com and hotmail.com, if you logged in msn.com, and open hotmail.com, you can see you've already logged in.

我正在使用 CI ,对于登录信息,我使用了CI的会话功能(实际上是 cookie ),但是似乎无法跨不同的域共享Cookie.

I'm using CI, and for login information I used CI's session functions (which is cookie in fact), but seems cookies cannot be shared cross different domains.

我尝试使用CURL,但是CURL无法使xyz.com 确实成为cookie.

I've tried to use CURL, but CURL cannot make xyz.com really make the cookies.

我也在Google周围搜索过,很多人建议传递会话ID,但问题是abc.comxyz.com之间没有链接,我如何通过会话 >?如果我将会话ID存储在数据库中,那么如何确定哪个用户应使用该会话ID?通过IP显然不安全:D

And I've also searched around Google, many people suggested to pass a session id, but the problem is, there's no link between abc.com and xyz.com, how can I pass the session? If I store the session id in database, then how can I identify which user should use this session id? By IP is not secure obviously :D

请帮帮我!

推荐答案

您可以在xyz.com上打开一个将连接到abc.com的iframe,然后使用ajax/js将某种令牌从通过从iframe调用js函数来访问iframe.

You can open an iframe on xyz.com that will connect to abc.com, then use ajax/js to forward some sort of token to xyz.com from the iframe by calling a js function from the iframe.

因此它看起来像:

XYZ.com:

function authAbcUser(token) { 
    //During this function you will set a cookie for this user on XYZ.com
}
<iframe height="0" width="0" src="http://www.abc.com/auth.php?token"></iframe>

ABC.com/auth.php:

ABC.com/auth.php:

parent.authAbcUser(token);

这篇关于如何一次登录不同域中的多个应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆