I have two sites. I want their token to be shared. How can I do that?

I have two sites, and after they log in, they will generate a token, to determine whether the authentication is successful. The next API request can be made with token, or only if it is required.

but how can I achieve token sharing between the two sites?

Mar.28,2021

P3P technology was used a long time ago to set up cross-domain cookie.

oauth or other authentication schemes should be more popular now. It is suggested that such a scheme should be adopted.


just make the configuration of the token of the two sites the same. In this way, the information from parsing token is the same. If you cache token, use the same cache server


foreground to store token in the browser's localStorage. LocalStorage can be called in different windows of the same browser, and then connect the tables of the two sites in the background, or simply request the same interface.
PS: stored value: localStorage.setItem (name, xxxxxx)
value: let anything = localStorage.getItem (name)


without cross-domain, cookie, localStorage and sessionStorage can be implemented in three ways, as long as you store it, you can read it. In the case of cross-domain, I am sorry.


We are saving httpOnly cookie, now, but your two sites must be the same superdomain, such as xxx.. Haha .com, yyy. Ha ha. Com. Cookie is stored under .com.


there are many mature solutions for single sign-on, and the basic flow is almost as follows:
1. First solve the cross-domain problem
2. Multiple sites use the same token verification and generation scheme, for example, you can use jwt
3.token to exist in cookie or localStorage
4. Communication between multiple sites, put the token in the request header or splice it into the URL parameter and pass it out
5. After the site gets the token, complete the login status Synchronize

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e9ed-e97a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e9ed-e97a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?