具有空令牌的Firebase电话验证响应

时间:2017-09-10 19:09:48

标签: android firebase firebase-authentication token digits

我正在按照以下官方链接将Digits身份验证迁移到Firebase身份验证:

从Firebase控制台导出的

google-services.json文件已集成到项目中。

我正在使用带有UI的插件解决方案,这是我的代码:

startActivityForResult(
                AuthUI.getInstance()
                        .createSignInIntentBuilder()
                        .setProviders(Arrays.asList(
                                new AuthUI.IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER).build())).build(), RC_SIGN_IN);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        IdpResponse response = IdpResponse.fromResultIntent(data);

        // Successfully signed in
        if (resultCode == RESULT_OK) {
            IdpResponse idpResponse = IdpResponse.fromResultIntent(data);

            //Here retreive the token from the response
            idpResponse.getIdpToken();
            finish();
            return;
        } else {
            // Sign in failed
            if (response == null) {
                // User pressed back button
                return;
            }

            if (response.getErrorCode() == ErrorCodes.NO_NETWORK) {
                Toast.makeText(this, getString(R.string.connection_error), Toast.LENGTH_SHORT).show();
                return;
            }

            if (response.getErrorCode() == ErrorCodes.UNKNOWN_ERROR) {
                Toast.makeText(this, getString(R.string.error_default), Toast.LENGTH_SHORT).show();
                return;
            }
        }

        Toast.makeText(this, "Error", Toast.LENGTH_SHORT).show();
    }
}

这是build.gradle的有趣部分:

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.1'

}

compile 'com.firebaseui:firebase-ui-auth:2.3.0'
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:support-v4:26.0.1'
compile 'com.android.support:recyclerview-v7:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:support-core-utils:26.0.1'
compile 'com.android.support:support-annotations:26.0.1'
compile 'com.android.support:percent:26.0.1'

当触发onActivityResult时,响应成功但令牌始终为空。

我不知道是否使用此身份验证提供程序,此令牌始终为空或我做错了。

2 个答案:

答案 0 :(得分:1)

您需要明确请求令牌。

请参阅https://firebase.google.com/docs/auth/admin/verify-id-tokens

FirebaseUser mUser = FirebaseAuth.getInstance().getCurrentUser();
mUser.getToken(true)

答案 1 :(得分:0)

如果登录成功,您应该有Firebase Auth用户。在这种情况下,没有IDP令牌,您应该只能检索用户:

FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();