I'm attempting to have one GCP Firebase Cloud Function call another. I am using https://cloud.google.com/functions/docs/securing/authenticating#authenticating_function_to_function_calls as the guide. I have everything working but when the function is invoked, it throws the following error:
Failed to validate auth token. FirebaseAuthError: Firebase ID token has incorrect "aud" (audience) claim. Expected "{projectId}" but got "https://{project-region}-{projectId}.cloudfunctions.net/{functionName}". Make sure the ID token comes from the same Firebase project as the service account used to authenticate this SDK.
I attempted to set the targetAudience
to {projectId}
, but then auth.getIdTokenClient(targetAudience);
failed with a 401 Unauthorized
response.
The called/invoked function is using functions.https.onCall
to authenticate the request. If I switch it to functions.https.onRequest
, it works, but I don't know how to validate the request and I think that's a pretty poor workaround anyway as it should be working with the onCall
method.
For the functions.https.onRequest
method, it passes through a Google Auth signed JWT Authorization header, but const decodedToken = await admin.auth().verifyIdToken(req.headers.authorization ?? '');
(source) fails with the error:
Error: Decoding Firebase ID token failed. Make sure you passed the entire string JWT which represents an ID token.