DEV Community

Discussion on: How to share Firebase Authentication across subdomains

Collapse
 
mikgross profile image
Mikael

Do you know if the following would work?

1) In the auth.domain.com app, authenticate the user and get a token
2) redirect the user to app.domain.com with a parameter that is set to be the token
3) check the token provided by extending the Function service from auth.domain.com project to app.domain.com
4) if valid perform new authentication from app.domain.com and issue new token to user (I guess this would not allow users to have multiple clients openned and working at the same time -- does the shared cookie solves this issue?)

Collapse
 
johncarroll profile image
John Carroll

My guess is no. For one, it sounds like someone would need to re-login each time they navigated to a new subdomain.

Collapse
 
mikgross profile image
Mikael

That's correct.

To circumvent setting a cookie in Functions and the problem of passing them through to the client, couldn't we just pass the cookie ID in the response, and set it at client level? Am I missing a security issue? That would relive me of a big pain...

Thread Thread
 
johncarroll profile image
John Carroll • Edited

Well the entire purpose of this post is to share sign in status between subdomains, and you’re not doing that (in your proposal at least).

Thread Thread
 
mikgross profile image
Mikael

Maybe I am misunderstanding something here or badly expressing myself..

What I am doing atm:
1) Sign-in and get token ID from the client
2) send the token ID to functions, validate token ID, generate session cookie and a jwt token in Functions, return the two values to the client
3) in the client set the two cookies for domain *.domain.com
4) all cookies are available accross all subdomains (tested), so I can perform the authchecks required

Something I am missing?

Thread Thread
 
johncarroll profile image
John Carroll • Edited

That sounds good. Sounds like the same thing this blog post suggests. Honestly though, I'm no security expert. I'm confident enough that following the steps in this post will work and is secure (after having spent a while researching it), but I have no advice if you are looking to do some variation of this.

This post is really just a summary of my findings after spending a week working on this problem. Beyond what's here though, you're on your own.