How to get an identifier token from FirebaseAuth

I am reading some Json files from a firebase database, and I am trying to get the ID token for the current user, which will be used in the header as follows:

 var response = await httpClient.get(url,headers: {'Authorization':"Bearer ${FirebaseAuth.instance.currentUser.getToken()}"});

when I do the previous line, it seems that it is not getting the correct token, since I cannot access the database, however, when I manually include the ID token in the line, my application works as intended. What exactly am I doing wrong?

+9
source share
2 answers

getIdToken()returns Future- you need awaitto get the token string:

var token = await FirebaseAuth.instance.currentUser().getIdToken();
var response = await httpClient.get(url,headers: {'Authorization':"Bearer $token"});
+10
source

U id , , :

const idToken = window.gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse().id_token
0

Source: https://habr.com/ru/post/1683227/


All Articles