22

I am looking for the Firebase to be authenticated seamlessly across multiple projects with different auth providers.

Example.

Suppose I have a website with 10 pages, with different data coming from 2 firebase projects ( project-1, project-2)

project-1 contains all the Users accounts

When I sign up/Login into firebase project (project-1). I am using Google/Phone/Password/Facebook. this creates users account if not exists.

Now I can see the data coming from the firebase (project-1).

Now few of my pages website want to access data from the project-2.

How to maintain the authentication state across the 2 projects so that, project-2 will get authenticated seamlessly with out prompting signup again. Probably with the same auth token which already created for project-1

I read this blog which was created by Ian Barber Working with multiple Firebase projects in an Android app. Which is only discussed about the google and android case only.

Thanks.

nagabandaru
  • 525
  • 5
  • 18
  • That blog is pretty much the only reference that discusses the use of multiple projects. It should be the same for other platforms using whatever APIs they use for doing custom initialization of the Firebase client SDK. – Doug Stevenson Sep 03 '17 at 20:00
  • 4
    Were you able to find a solution for this ? I have exactly the same problem to handle – Kishan B Jan 27 '19 at 13:25
  • Has anyone found a solution for this? I am also stuck in a similar situation. – Adit Luhadia Apr 05 '21 at 19:11
  • 1
    The solution would be to create a server that uses `firebase-admin` of 2 instances to create/update user data in other project when user logins in 1st project – p2pdops Jun 15 '21 at 03:53
  • You are looking a SSO (Single Sing On) solution. You can probably design something using an "authentication service" then share tokens between apps. I know it's a default option with Auth0 : https://auth0.com/docs/sso – BorisD Jul 24 '21 at 10:08

1 Answers1

1

You can use a combination of firebase-admin on a server and a custom firebase token as described here.

Essentially, you can get a user's JWT token for your first app using the methods described in this answer. Then you could make a request to your own server that would validate that your JWT token originated from your first project and could then issue you a second JWT token you can use to authenticate with the second project.

Inbar Koursh
  • 509
  • 4
  • 16
  • can you explain the later part? I tried using `signInWithCustomToken` from the firebase javascript SDK, using project one token to sign in with project two but that didn't work at all ("auth/invalid-custom-token ... The custom token format is incorrect"). – Andresch Serj Oct 25 '21 at 12:14
  • Please post a new question with more information about your specific problem. I referenced using the admin SDK to generate a new JWT token for the second app, after validating the JWT token for the first on a server. Do note that you can't simply transfer JWT tokens from app to app. – Inbar Koursh Oct 25 '21 at 14:15