[英]Firebase phone auth response with null token
I am migrating the Digits authentication to Firebase authentication following these official links: 我通过以下官方链接将Digits身份验证迁移到Firebase身份验证:
google-services.json
file exported from Firebase console is integrated on the project. 从Firebase控制台导出的
google-services.json
文件已集成到项目中。
I am using the drop-in solution with UI and this is my code: 我正在使用带有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();
}
}
And this is the interesting part of the build.gradle: 这是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'
When onActivityResult is fired, the response is successful but the token always is null. 触发onActivityResult时,响应成功,但令牌始终为null。
I don't know if with this authentication provider, this token it's always null or I'm doing something wrong. 我不知道是否使用此身份验证提供程序,此令牌始终为null或做错了什么。
You'll need to explicitly request for the token. 您需要明确请求令牌。
See https://firebase.google.com/docs/auth/admin/verify-id-tokens : 请参阅https://firebase.google.com/docs/auth/admin/verify-id-tokens :
FirebaseUser mUser = FirebaseAuth.getInstance().getCurrentUser();
mUser.getToken(true)
If the sign in was successful, you should have a Firebase Auth user available. 如果登录成功,则您应该有一个Firebase Auth用户可用。 In this case there is no IDP token, and you should be able to just retrieve the user:
在这种情况下,没有IDP令牌,您应该能够检索用户:
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.