Last active
April 2, 2020 12:57
-
-
Save anotherdev/40181800d38e2de0e9afa50c6d4e12d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Firebase Auth REST SDK Android integration | |
Requirements: | |
1. Minimum Android API 21 | |
2. Enable Java 8 | |
Steps: |
Example project: firebase-auth-rest
Steps:
- Replace
com.google.firebase.auth.FirebaseAuth
withcom.anotherdev.firebase.auth.common.FirebaseAuth
.
FirebaseApp app = FirebaseApp.getInstance();
com.anotherdev.firebase.auth.common.FirebaseAuth auth = FirebaseAuthRest.getInstance(app);
- Sign in anonymously function:
auth.signInAnonymously().subscribe();
- Facebook Login function:
com.facebook.login.LoginResult fb;
String token = fb.getAccessToken().getToken();
// https://console.firebase.google.com/u/0/project/<your-app>/authentication/providers -> click on Facebook
String oAuthRedirectUri = "https://<your-app>.firebaseapp.com/__/auth/handler";
AuthCredential credential = com.anotherdev.firebase.auth.provider.FacebookAuthProvider.getCredential(token, oAuthRedirectUri);
auth.signInWithCredential(credential).subscribe();
- Google Sign-In function:
GoogleSignInClient google;
startActivityForResult(google.getSignInIntent(), REQ_GOOGLE_SIGN_IN);
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
GoogleSignInAccount acc = GoogleSignIn.getSignedInAccountFromIntent(data).getResult();
AuthCredential credential = com.anotherdev.firebase.auth.provider.GoogleAuthProvider.getCredential(acc.getIdToken());
auth.signInWithCredential(credential).subscribe();
}
- Listen to user login/logout:
auth.authStateChanges()
.doOnNext(auth -> Log.i("FAR", "user auth state changed!"))
.subscribe();
- Logout function:
auth.signOut();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup the Firebase Auth REST SDK
Where x.y.z = latest Firebase Auth REST SDK on