I think the Firebase Admin SDK is missing a very important function (or maybe its documentation).
TL; DR : How can you refresh custom token with the Admin SDK?
The documentation (https://firebase.google.com/docs/auth/admin/manage-sessions) says:
Firebase Authentication sessions are long lived. Every time a user signs in, the user credentials are sent to the Firebase Authentication backend and exchanged for a Firebase ID token (a JWT) and refresh token. Firebase ID tokens are short lived and last for an hour; the refresh token can be used to retrieve new ID tokens.
Ok. But how? There is no mention how to replace the refresh token with a new custom token. There are lots of documentation regarding how you can revoke a refresh token etc...
There is however a REST api function that says, (https://firebase.google.com/docs/reference/rest/auth/#section-refresh-token)
Exchange a refresh token for an ID token You can refresh a Firebase ID token by issuing an HTTP POST request to the securetoken.googleapis.com endpoint.
However, the access_token (JWT) you get from this API call is not accepted neither. And the format of the JWT's are not even similar. Below are two samples of custom tokens retrieved (decoded) : i. with the admin.auth().createCustomToken(uid) method of Admin SDK
{
"uid": "9N5veUXXXXX7eHOLB4ilwFexQs42",
"iat": 1521047461,
"exp": 1521051061,
"aud": "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
"iss": "[email protected]",
"sub": "[email protected]"
}
ii. with the https://securetoken.googleapis.com/v1/token?key=[API_KEY] call
{
"iss": "https://securetoken.google.com/XXX",
"aud": "XXX",
"auth_time": 1521047461,
"user_id": "9N5veUXXXXX7eHOLB4ilwFexQs42",
"sub": "9N5veUXXXXX7eHOLB4ilwFexQs42",
"iat": 1521051719,
"exp": 1521055319,
"email": "[email protected]",
"email_verified": false,
"firebase": {
"identities": {
"email": [
"[email protected]"
]
},
"sign_in_provider": "password"
}
}
There are plenty of questions raised about this topic. Maybe someone from Firebase team can answer it once and for all. See the links below
Thanks for your time!!