Search code examples
firebasefirebase-authenticationgoogle-oauthrefresh-token

How to get a firebase refresh token


In the documentation at https://firebase.google.com/docs/reference/rest/auth#section-refresh-token below this sample request curl

curl 'https://securetoken.googleapis.com/v1/token?key=[API_KEY]' \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data 'grant_type=refresh_token&refresh_token=[REFRESH_TOKEN]'

it is mentioned that In the example above, you would replace [API_KEY] with the Web API Key of your Firebase project, [REFRESH_TOKEN] with the Firebase refresh token. I can get the API_KEY from https://console.cloud.google.com/apis/credentials

BUT where do I get this REFRESH_TOKEN from?


UPDATE: just realized (after a good night sleep) I had the following already in my page

const firebase = initializeApp(firebaseConfig);
const auth = getAuth(firebase);
...
auth.currentUser.getIdToken(false)

All I had to do was

auth.currentUser.refreshToken

Solution

  • The refresh_token is already included in the authentication API call response (whether it is SignInWithEmail, AnonymousSignIn, etc..).

    You can consume this refresh token only once in order to get a new one.
    It is your responsibility to save that refresh_token in order to consume it later.