Firebase: can I use the new Facebook account to authenticate application users?

Facebook just introduced the Account Suite at F8 2016.

It allows users of the application to register using their phone number or email address.

I already tried to use its returned access token for authentication with regular Facebook login for Firebase, but this did not work.

Is there a way to authenticate application users using Firebase using the Facebook Account Kit?

Additional Information

I can log in through the Account Kit and get the access token with AccountKit.getCurrentAccessToken();

Then I try to authenticate using Firebase using an access token:

Option 1)

mFirebaseRef.authWithOAuthToken("facebook", accessToken.getToken(), new AuthResultHandler("facebook"));

-> FirebaseError: Invalid authentication credentials.

Option 2)

mFirebaseRef.authWithCustomToken(accessToken.getToken(), new Firebase.AuthResultHandler() { ... }

-> FirebaseError: Login Failed - failed to parse authentication token.

(Btw. The access token string is half the length of the token that is generated if I log in using the regular Facebook login button.)

I wonder if I can already use the token generated by the set of accounts for authentication with Firebase?

-

(By the way, I also tried to get an answer here: https://groups.google.com/forum/#!topic/firebase-talk/qrb1gWBKO3M )

+5
source share
2 answers

Yes, this is possible with Firebase Custom Authentication .

You need to set up an authentication server that can create custom Firebase tokens using an account user ID or phone number as uid.

Once you get the user token from the authentication server, you then use it to log in to firebase as follows:

 mAuth.signInWithCustomToken(mCustomToken) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { Log.d(TAG, "signInWithCustomToken:onComplete:" + task.isSuccessful()); if (!task.isSuccessful()) { Log.w(TAG, "signInWithCustomToken", task.getException()); Toast.makeText(CustomAuthActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } } }); 

This blog post contains a detailed step-by-step guide on how to implement it.

+5
source

I got the following response on Firebase Google Group :

Yes, after a discussion with another Firebase engineer, I'm sure Firebase Authentication does not actually support a set of accounts. I'm sorry. We do not plan to support him in the work, but we will reconsider if we get enough people asking for it.

+3
source

Source: https://habr.com/ru/post/1247031/


All Articles