I have an Android app with a few activities and a long-running service. The service has some model classes, POJOs that are stored in a Firebase Database.
On first run, the app determines that the the user hasn't logged in yet and uses FirebaseUI-Android to offer an account picker activity with Google and Facebook on it. This is pretty common:
Intent signInIntent = AuthUI.getInstance().createSignInIntentBuilder()
.setProviders(Arrays.asList(
new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER).build()))
.setTheme(R.style.AppThemeFirebaseAuth)
.setLogo(R.drawable.logo)
.setIsSmartLockEnabled(!BuildConfig.DEBUG)
.build();
activity.startActivityForResult(signInIntent, Request.FIREBASE_AUTH);
I can then get a FirebaseUser
and start doing stuff with the database.
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference firebaseUserRef = FirebaseDatabase.getInstance().getReference("users").child(firebaseUser.getUid());
The problem arises on the next run of the service, which may be when no activity is around. I would like to do some database operations again, but without any user interaction. Looks like I need to call FirebaseAuth.signInWithCredential()
, but where do I get the AuthCredential
reference? The AuthCredential
is not passed back to the activity that starts sign in.
Can I use the Smart Lock stuff in FirebaseUI-Android to help here?
You can't. From this thread https://github.com/firebase/FirebaseUI-Android/issues/123
Ah, we have a slight problem here after discussing this with some colleagues. There is deliberately no way to get back an AuthCredential from an existing user, to avoid potentially leaking credentials. So, the linking of the authentication method to the anonymous account would have to occur within Firebase UI if you are using the library. I'll take a look at this next week to get you unblocked ASAP