I’m encountering an issue with Firebase authentication on my backend. My frontend team and I are using Firebase Authentication to authenticate users with Google, but I’m getting the following error:
Google authentication failed: Firebase ID token has incorrect "aud" (audience) claim. Expected "bitpic" but got "1018060832031-v397dko55bp73mgr6r35hbvfkellsc7e.apps.googleusercontent". Make sure the ID token comes from the same Firebase project as the service account used to authenticate this SDK. See for details on how to retrieve ID token.
What I’ve Tried:
- Verified that the frontend is sending the correct token to the backend.
- Checked that both the frontend and backend are using the same Firebase project.
- Consulted the Firebase documentation, but still unable to resolve the mismatch.
cred = credentials.Certificate(settings.FIREBASE_ADMIN_SDK_PATH)
firebase_admin.initialize_app(cred)
print("Current App Name:", firebase_admin.get_app().project_id)
async def verify_google_token(id_token: str):
try:
decoded_token = auth.verify_id_token(id_token)
return decoded_token
except Exception as e:
raise_http_exception(400, f"Google authentication failed: {str(e)}")
This function is meant to verify the ID token received from the frontend. However, I’m seeing the error about a mismatch in the audience (aud) claim between the token and my Firebase project.