5

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
jombie
  • 231
  • 2
  • 8

2 Answers2

1

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.

Torello
  • 936
  • 11
  • 15
  • "If you will need more info about realization - leave a comment, and I will share details of my realization." Hello! I tried to figure out how to implement cross app authentication in Android using Firebase Auth, but have no idea. If it is possible, do you know what FirebaseAuth state can I share from one App1 to App2 (so, App2 can do auto-login using FirebaseAuth state from App1)? For instance, token from FirebaseAuth cannot be used (because it is short-lived token, that expires in 1 hour). Thank you for the answer in advance! – arhipov slava Aug 30 '23 at 15:24
  • So in my place the process looks like this: 1) Use firebase auth to create user account or log user in. 2) When the user logged in - create it's profile on server via firestore database, and use user uid as key. 3) Store user uid locally (share it between your apps), and use it to retrive info from server. You can get example of user id use here: https://stackoverflow.com/a/38354441/1729202 – Torello Aug 30 '23 at 16:39
  • Got it! it means, in App2 (when we want to do autologin) we don't need to use FirebaseAuth class at all. Thank you very much for the answer! – arhipov slava Aug 31 '23 at 17:12
0

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.

Satish Babariya
  • 3,062
  • 1
  • 15
  • 29
  • 7
    I know that I can use the same project but I was asking If I install Demo_iOS1 app and login using firebase and then I install Demo_iOS2 app then can I use the already logged in credentials without asking the user to login in the second app. – jombie Nov 13 '17 at 08:49