Firebase:我可以使用Facebook的新帐户套件对应用用户进行身份验证吗? [英] Firebase: Can I use Facebook's new Account Kit to authenticate app users?

查看:178
本文介绍了Firebase:我可以使用Facebook的新帐户套件对应用用户进行身份验证吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Facebook在2016年F8推出了账户套件



它使应用程序用户可以使用他们的电话号码或电子邮件地址登录。



我已经尝试使用它的返回访问令牌进行身份验证Facebook的常规Facebook登录,但它没有工作。



是否已经有一种方法来使用Facebook帐户工具包使用Firebase验证应用用户?



附加信息



我可以通过帐户工具包登录,并通过 AccountKit.getCurrentAccessToken();



然后尝试使用访问令牌对Firebase进行身份验证:



选项1)

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



- > FirebaseError:提供的验证凭证无效。



选项2)

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



- > FirebaseError:登录失败 - 无法解析身份验证令牌。 b $ b

(Btw。访问令牌字符串是我使用常规Facebook登录按钮登录时生成的令牌长度的一半。)

不知道我是否已经可以使用生成的令牌通过帐户工具包来验证与Firebase的?

-



(btw。我也试图得到一个请在这里回答: https://groups.google.com/forum/#! topic / firebase-talk / qrb1gWBKO3M

解决方案

可以使用 Firebase自定义身份验证



您需要设置一个可以创建Firebase自定义令牌的认证服务器,使用accountkit用户ID或电话号码作为uid。

一旦从认证服务器收到自定义令牌,使用它来登录到firebase像这样:



<$ p $ (@NonNull Task< AuthResult>()){
@Override
public void onComplete(@NonNull Task< AuthResult> ;任务){
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();
}
}
});

blog post 有详细的分步指南如何实现它。


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.

这篇关于Firebase:我可以使用Facebook的新帐户套件对应用用户进行身份验证吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆