How to get the refresh token from Firebase.auth.currentUser Android Kotlin
Asked Answered
T

3

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.

Turgeon answered 20/10, 2020 at 17:11 Comment(3)
Hey, did you found the answer? I'm in the same position right nowTent
me2, I keep fetching the wrong data because of that..Picked
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.Turgeon
P
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://mcmap.net/q/1350636/-firebase-when-should-i-use-refreshtoken

Picked answered 8/1, 2022 at 14:4 Comment(0)
F
1

Read this answer https://mcmap.net/q/770368/-android-studio-get-firebase-token-from-getidtoken

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
}
Fsh answered 14/2, 2022 at 19:31 Comment(0)
A
0

firebaseUser. getIdToken() reloads your token

Alkyl answered 1/9, 2021 at 22:42 Comment(1)
Please add further details to expand on your answer, such as working code or documentation citations.Beltz

© 2022 - 2024 — McMap. All rights reserved.