简体   繁体   中英

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.

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. The information contained is non sensitive(password/id) and would just let me know who the user is via a publicID.

Im using nodejs and redis for my sessions.

Things I have tried:

1) Iframes, postMessage, localStorage:

-User sends session info from site1.com to iframe on the same page containing "site2.com" via PostMessage. 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.

The error I got, was unable to save localStorage on other domain by sending postMessage from site1.com to the site2.com iframe.

On site1.com I have an iframe showing site2.com, where site2.com is my server that will save the session.

2) CORS ajax: was not able to save/remember session


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.

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. This might be a helpful read:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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