How to get the ID token from FirebaseAuth
getIdToken()
returns a Future
- you have to await
it to actually get the token string:
var token = await FirebaseAuth.instance.currentUser().getIdToken();
var response = await httpClient.get(url,headers: {'Authorization':"Bearer $token"});
U can also retrieve the id token from the window object like so:
const idToken = window.gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse().id_token
I think that there is a bug in Flutter.
Now to call the method getIdToken()
you need to do this:
FirebaseUser user = await FirebaseAuth.instance.currentUser();
String token;
user.getIdToken().then((result) {
token = result.token;
});
You can't call FirebaseAuth.instance.currentUser().getIdToken()