After a successful login, I am unable to get the id token using the getIdToken() method. This method returns a task and the task never completes. Using basic email id/password authentication using Firebase Auth UI in an android app.
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. How to wait for this task? This code used to work when for firebase-UI-auth:3.2.2. Now I am trying to upgrade this library to 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.
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.