简体   繁体   English

如何在不同网站之间共享数据变量或本地存储? IFRAME?postMessage的?

[英]How can I share a data variable or localstorage across different websites? iframe?postMessage?

I am trying to get session data between different websites, similar to what stackexchange does with all its sister sites, in which I login once and my session is detected on the other sites. 我正在尝试获取不同网站之间的会话数据,类似于stackexchange对其所有姊妹站点进行的操作,在该站点中我登录一次,并在其他站点上检测到我的会话。

But the difference is I would need to create a session on www.site1.com and access it on www.site2.com, and also would post this code on 3rd party sites to still access the session from their site. 但是不同之处在于,我将需要在www.site1.com上创建一个会话并在www.site2.com上进行访问,并且还要将此代码发布在第三方网站上,以便仍然可以从其站点访问该会话。 The information contained is non sensitive(password/id) and would just let me know who the user is via a publicID. 所包含的信息是不敏感的(密码/ ID),并且只会通过publicID让我知道用户是谁。

Im using nodejs and redis for my sessions. 我在会话中使用nodejs和redis。

Things I have tried: 我尝试过的事情:

1) Iframes, postMessage, localStorage: 1)iframe,postMessage,localStorage:

-User sends session info from site1.com to iframe on the same page containing "site2.com" via PostMessage. -用户通过PostMessage将会话信息从site1.com发送到包含“ site2.com”的同一页面上的iframe。 On site2.com, when I receive the message, I am attempting to save to site2.com localstorage, the goal is to access site2.com session from any other websites having the site2.com iframe on their page. 在site2.com上,当我收到消息时,我试图保存到site2.com的localstorage,目标是从页面上具有site2.com iframe的任何其他网站访问site2.com会话。

The error I got, was unable to save localStorage on other domain by sending postMessage from site1.com to the site2.com iframe. 我收到的错误无法通过将postMessage从site1.com发送到site2.com iframe来将localStorage保存在其他域上。

On site1.com I have an iframe showing site2.com, where site2.com is my server that will save the session. 在site1.com上,我有一个iframe,显示的是site2.com,其中site2.com是我的服务器,它将保存会话。

2) CORS ajax: was not able to save/remember session 2)CORS ajax:无法保存/记住会话


I've heard of browser fingerprinting, like how facebook/google can track users across sites and this may be the type of solution i need. 我听说过浏览器指纹识别,例如facebook / google如何在站点之间跟踪用户,这可能是我需要的解决方案类型。

Can someone please let me know what I can try different? 有人可以让我知道我可以尝试什么吗? Thanks. 谢谢。

You could maybe use access tokens stored on the cookies or passed on the url, similar to the way RESTful apps work. 您可能使用存储在cookie上或通过url传递的访问令牌,类似于RESTful应用程序的工作方式。 This might be a helpful read: 这可能对您有帮助:

http://www.sitepoint.com/using-json-web-tokens-node-js/ http://www.sitepoint.com/using-json-web-tokens-node-js/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM