Home > other >  How To Verify Firebase ID Token Using Cloud Run and Swift?
How To Verify Firebase ID Token Using Cloud Run and Swift?

Time:12-28

So I know this question has sort of been asked and some answers were given on Github but they don't seem to apply to my use case. I have also tried searching here on Stack Overflow and cant seem to find the answer to a question I would have though would've been asked.

So I am using Swift on the Frontend and I am passing in an ID token like so:

let userIDToken = try await signIn.result?.user.getIDToken() ?? ""
await web.webCall(endpoint: userIDToken)

and I am using Express/Cloud Run on the backend and verifying my token like this:

let idToken = await admin.auth().verifyIdToken(req.body.idToken);
const uid = idToken.uid;

console.log(uid);

However, I am getting the following error message:

FirebaseAuthError: Firebase ID token has no "kid" claim. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token.

When I go to that URL, it tells me to do exactly what Im doing so what am I doing wrong? Can someone please explain this to me because first off I am not creating a custom token as referenced here:

Firebase 3.0 Tokens : [Error: Firebase Auth ID token has no "kid" claim]

I am just logging the user in using the following piece of code:

Auth.auth().signIn(withEmail: email, password: password)

and I seen this here:

https://github.com/firebase/firebase-tools/issues/2764

However, if this doesn't work outside of the cloud functions emulator then how would I sign in on the frontend and verify that the user is authenticated/logged in inside of my cloud run functions?

Any help with this would be appreciated. Thank you.

CodePudding user response:

Turns out the all I needed to do the entire time was set the firebase auth emulator host in the environment variables. So anyone running into this problem in the future you can set the following and it should work fine:

FIREBASE_AUTH_EMULATOR_HOST=localhost:9099

  • Related