简体   繁体   中英

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 )

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM