I'd like to build an Android app using Firebase. Firebase provides demo code for a login screen https://github.com/firebase/firebase-login-demo-android .
But rather than making the user type in their account info, I'd like the user to be able to use the account(s) info that the user already entered in Android's centralized account manager.
I've seen the docs of the AccountManager
object at https://developer.android.com/reference/android/accounts/AccountManager.html and the Firebase android authentication guide at https://www.firebase.com/docs/android/guide/user-auth.html, but I'm too much of a noob to grok how to put it all together.
Any advice/pointers/sample code would be appreciated. Or let me know if I'm barking up the wrong tree.
Firebase engineer here,
This is a totally legitimate way of doing this--we've had a number of people choose to integrate this in the past.
The short answer is that it requires two steps:
Looks like this is a good resource for the first step (learning about AccountManager). Then in the doCoolAuthenticatedStuff() you would follow our typical auth flow:
Firebase ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.authWithOAuthToken("google", "<OAuth Token>", new Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
// the Google user is now authenticated with your Firebase app
}
@Override
public void onAuthenticationError(FirebaseError firebaseError) {
// there was an error
}
});
For Google, we use 'email' scope, but each provider will be different.
I have an example of something similar in iOS world (Twitter login using ACAccountStore, which is very similar to the Android AccountManager), if the flow helps at all.
This sounds like it would make a good recipe/gist though, so I'll see what I can do!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With