[英]Firebase Auth UI Android, task returned by getIdToken() never completes
After a successful login, I am unable to get the id token using the getIdToken() method.成功登录后,我无法使用 getIdToken() 方法获取 ID 令牌。 This method returns a task and the task never completes.
此方法返回一个任务,而该任务永远不会完成。 Using basic email id/password authentication using Firebase Auth UI in an android app.
在 Android 应用程序中使用 Firebase Auth UI 使用基本电子邮件 ID/密码身份验证。
new AuthUI.IdpConfig.EmailBuilder().build()
Here is the library version:这是库版本:
implementation 'com.firebaseui:firebase-ui-auth:6.1.0'
Here is how I am fetching the token:这是我获取令牌的方式:
public String getIdToken(){
String token = null;
Task<GetTokenResult> task = FirebaseAuth.getInstance().getCurrentUser().getIdToken(true);
while(!task.isComplete()){
}
if(task.isSuccessful()){
token = task.getResult().getToken();
}else{
token = "token_gen_failed";
}
return token;
}
The while loop never ends as the task never completes. while 循环永远不会结束,因为任务永远不会完成。 How to wait for this task?
如何等待这个任务? This code used to work when for firebase-UI-auth:3.2.2.
此代码用于 firebase-UI-auth:3.2.2。 Now I am trying to upgrade this library to 6.1.0.
现在我正在尝试将这个库升级到 6.1.0。
Any help here please, tried so many things.请在这里提供任何帮助,尝试了很多东西。
All I see in the log is this:我在日志中看到的是:
D/FirebaseAuth: Notifying id token listeners about user ( xxxxxxxxxx ).
You can do it like你可以这样做
task.addOnCompleteListener(task -> {
if(task.isSuccessful() & task.getResult() != null){
token = task.getResult().getToken();
}else{
token = "token_gen_failed";
}
//do here whatever you want to do with token;
}
If you want to use this as a separate function then let me know.如果您想将其用作单独的功能,请告诉我。 You have to do some extra task for it.
你必须为它做一些额外的任务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.