I use firebase for authentication on my website and I want to keep the users auth session active across subdomains.
Unfortunately, firebase uses Local Storage to sto
After having spent much longer then I intended to getting single-sign-in working across subdomains, I wrote up a blog post detailing how to accomplish this.
We have three applications at different domains.
accounts.domain.com
app1.domain.com
app2.domain.com
We have three Firebase Functions
...cloudfunctions.net/users-signin
...cloudfunctions.net/users-checkAuthStatus
...cloudfunctions.net/users-signout
In order to sign in:
accounts.domain.com
app/users-signin
cloud function which verifies the information and, if valid, sets a signed __session
cookie which contains the user's UID and returns a success indication to the client./users-checkAuthStatus
cloud function which looks for the signed __session
cookie, extracts the user UID, and uses the UID and the firebase-admin SDK to mint a custom auth token which it returns to the client.app1.domain.com
, the app first checks to see if the person is already signed in using the firebase javascript SDK.
/users-checkAuthStatus
cloud function which looks for the signed __session
cookie and returns a custom auth token to the client if a valid __session
cookie is found.
Again, this is a high level overview which ignores issues like cross-site-scripting attacks, actually signing out, etc. For more information, check out the blog post.