Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase: Can I use Facebook's new Account Kit to authenticate app users?

Facebook just introduced Account Kit at F8 2016.

It enables app users to log in using their phone number or email address.

I already tried to use it's returned access token to authenticate with the regular Facebook log in for Firebase, but it didn't work.

Is there already a way to authenticate app users with Firebase using Facebook Account Kit?

Additional Info

I can login via Account Kit and receive an access token with AccountKit.getCurrentAccessToken();

I then try to authenticate with Firebase using the access token:

Option 1)

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

-> FirebaseError: Invalid authentication credentials provided.

Option 2)

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

-> FirebaseError: Login Failed - Could not parse auth token.

(Btw. the access token string is half the length of the token which is generated if I login using the regular Facebook Login button.)

I wonder if I already can use the token generated by the Account Kit to authenticate with Firebase?

--

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

like image 746
Steffen Avatar asked Apr 13 '16 11:04

Steffen


People also ask

What type of authentication can we build using Firebase authentication?

You can use Firebase Authentication to allow users to sign in to your app using one or more sign-in methods, including email address and password sign-in, and federated identity providers such as Google Sign-in and Facebook Login.

How do I authenticate on Firebase?

You can sign in users to your Firebase app either by using FirebaseUI as a complete drop-in auth solution or by using the Firebase Authentication SDK to manually integrate one or several sign-in methods into your app. The recommended way to add a complete sign-in system to your app.


2 Answers

Yes, it's possible using Firebase Custom Authentication.

You need to setup an authentication server which can create Firebase custom tokens, using the accountkit user id or phone number as the uid.

Once you receive the custom token from the authentication server, you then use it to sign into firebase like this:

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 has a detailed step-by-step guide on how to implement it.

like image 113
atimothee Avatar answered Sep 28 '22 07:09

atimothee


I got the following answer in the Firebase Google Group:

Yeah, after discussing with another Firebase engineer, I'm pretty sure Firebase Authentication does not actually support Account Kit. Sorry. We have no plans to support it in the works, but will revisit if we get enough people asking for it.

like image 25
Steffen Avatar answered Sep 28 '22 08:09

Steffen