I've got a GCP Cloud Function which validates authentication of Firebase Authentication, i.e. looking for an Authentication header with an idToken value. I want to write a script that will allow a user to authenticate and make a call to that function. This is what I currently have:
from google_auth_oauthlib import flow
import httpx
appflow = flow.InstalledAppFlow.from_client_secrets_file(
'client_secret.apps.googleusercontent.com.json',
scopes=['openid',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'],
)
creds = appflow.run_local_server()
print(creds.valid)
response = httpx.post(
'https://us-central1-myproject.cloudfunctions.net/myfunction',
headers={'Authorization': 'Bearer ' + creds.id_token}
)
print(response.status_code)
print(response.text)
I am getting an Unauthorized error from the Cloud Function when invoking the script and signing in with a valid user, and it looks like the Cloud Function fails to authenticate creds.id_token.
What am I missing?
EDIT
On the backend side, I decoded the verifyIdToken error and got the following:
Firebase ID token has incorrect "aud" (audience) claim.
I think this ID token is not the correct one.