Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase auth/invalid-custom-token

I am trying to generate custom tokens with the firebase admin sdk

const uid = '91f0bf4c-3e3c-441c-a21d-6a7fee341db5'
firebaseAdmin.auth().createCustomToken(uid)

With this specific uid sometimes the custom tokens work, other times when using authWithCustomToken() on the client side I get this error:

“auth/invalid-custom-token” The custom token format is incorrect. Please check the documentation."

Is there any way I can debug what is going on with the token? On the surface both the "good" tokens and the "bad" tokens look the same:

They have 3 parts, separated by a .

  • The first part is 36 characters long and in both the working case and the broken case it is the exact same
  • In both examples, the second part is 392 characters and they are almost the exact same
  • The both examples, the third part is 342 characters long and they are different.
like image 486
dylanjha Avatar asked Jul 14 '17 19:07

dylanjha


1 Answers

Can you go to https://jwt.io and decode your custom token. It should look like this:

{
  "uid": "some-uid",
  "iat": 1500147255,
  "exp": 1500150855,
  "aud": "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
  "iss": "firebaseserviceaccount@YOUR_PROJECT_ID.iam.gserviceaccount.com",
  "sub": "firebaseserviceaccount@YOUR_PROJECT_ID.iam.gserviceaccount.com"
}

YOUR_PROJECT_ID should match the same project on your client side project.

like image 157
bojeil Avatar answered Sep 22 '22 09:09

bojeil