6

I am breaking my head on how to get the refresh token from FirebaseAuth but cannot seem to find how.

On iOS, the equivalent is Auth.auth().currentUser?.refreshToken. Any help is highly appreciated.

Tal Zion
  • 6,308
  • 3
  • 50
  • 73
  • 2
    Hey, did you found the answer? I'm in the same position right now – David_E Jul 08 '21 at 18:32
  • me2, I keep fetching the wrong data because of that.. – Rafael Jan 08 '22 at 13:54
  • I think it’s just not possible. Firebase does not allow access to refresh token on Android. Maybe this is due to security reason where on iOS you can store it in KeyChaim. – Tal Zion Jan 08 '22 at 14:07

3 Answers3

2

I think this is what Furkan meant to say:

Use the forceRefresh parameter. This force refreshes the token. Should only be set to true if the token is invalidated

    FirebaseAuth.getInstance().currentUser!!.getIdToken(true)

Read this answer for when you should use it: https://stackoverflow.com/a/48599373/1772057

Rafael
  • 788
  • 2
  • 17
  • 38
1

Read this answer https://stackoverflow.com/a/45427901/6534576

Maybe you solution is use the getIdToken listener.

  • getIdToken(true) only if you want refresh the token

  • getIdToken(false) if you only want get the current

code

user.getIdToken(true).addOnSuccessListener { result ->
      val token = result.token
}
vibroto
  • 188
  • 1
  • 5
0

firebaseUser. getIdToken() reloads your token