Firebase auth state sharing between apps

Viewed 1071

I have a firebase project that contains multiple android apps and I use firebase authentication like email, google and Facebook. Now when users sign in into one of our app can I share that Sign In with the another app that user installs which is also present in the same firebase project.

2 Answers

You can easily set up cross app authentication in iOS while using Firebase Auth, using keychain sharing:

  1. Add keychain sharing capability in each app, where you want to use cross app authentication
  2. Define in your code, that you want to use keychain sharing
    do {
      try Auth.auth().useUserAccessGroup("TEAMID.com.example.group1")
    } catch let error as NSError {
      print("Error changing user access group: %@", error)
    }
  1. Sign in to firebase, using firebase auth in at least one application.
  2. The same current user is available in all apps, that use same access group:
    var user = Auth.auth().currentUser 

You will find more in official Firebase documentation: https://firebase.google.com/docs/auth/ios/single-sign-on?hl=en

For now I have no info about cross app authentication on Android, but I have a task to implement same thing on that platform. I will share details as soon as I implement that.

Edited: Ok I solve that puzzle with Android. For now, the only method that you can use to share auth state between apps on Android 10+ it's a ContentProvider. If you will need more info about realization - leave a comment, and I will share details of my realization.

Yes you can use same authentication in every app in same Project. it doesn't matter if its iOS/Android or two or many android apps as long as those are in same Firebase Project.

Here is one use case for you:

I have 4 Apps two Android and two iOS Apps

Bundle IDS are like this :

  1. Demo_iOS1 : com.ios.demo1
  2. Demo_iOS2 : com.ios.demo2

Note: All Four apps are in the same Firebase Project

Now If I Create User IN Demo1 iOS app, then I can login using that user credentials in all other 3 apps same goes for other conditions.

Related