0
votes

I am signing my firebase custom tokens based on the JSON doc I got from project settngs > Firebase admin SDK. The same code was working a few days ago and now it's giving me an error: The custom token format is incorrect. Please check the documentation.

I am using the same code snippet provided by firebase:


var admin = require("firebase-admin");

var serviceAccount = require("path/to/serviceAccountKey.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
});

And it worked in past, but now gives me this error! How do I solve this issue?

You state that you are "signing my firebase custom tokens", but this code just shows you initializing the Admin SDK. Is your problem to do with initialization with a service account credential or with Firebase Authentication Custom tokens? (if the latter, please add the code causing the error)samthecodingman
@samthecodingman My server signs custom tokens and send them to the client, when the client tries to make a request using these custom tokens, it gives this error at client side.Anurag Vohra
Quote from Jacob Wenger's excellent blog on Firebase Auth tokens: "Custom tokens have a singular purpose: authenticate client SDKs. ...the custom tokens themselves are not used to authenticate..." It seems your client is trying to use the custom token as an ID token. That's incorrect. Your client should use the custom token with the signInWithCustomToken() method and once signed in, use the getIdToken() method to get an ID token that they can use to authenticate with the back-end.erwinv
@erwinv My server signs these custom token using the firebase-admin API, so that the clients save it and later use it to access Firebase resources. Is it the wrong way to approach this problem ?Anurag Vohra