Skip to main content
Solved

IAP rejects identity token: "Invalid JWT audience" although aud matches the IAP OAuth client ID

  • Dec 4, 2026 5:45 AM UTC
  • 3 replies
  • 10 views

Alex-Doulapilot
Forum|alt.badge.img+2

Project: doulapilot-prod (1008190227773). Resource: Cloud Run service doulapilot-admin (us-west1) protected by IAP.

We are calling the service programmatically from another Cloud Run service using a Google identity token, per the documented programmatic-access flow. IAP rejects every token with: "Invalid IAP credentials: Invalid bearer token. Invalid JWT audience." (response header x-goog-iap-generated-response: true).
 

Facts, all verified 3 Dec 2026 ~20:50 PT:
- The OAuth client ID in IAP's own browser sign-in redirect for this resource is 369001918367-t5qrahnqdaasaifvk6akpqkpjk9vli58.apps.googleusercontent.com.
- The caller is service account doulapilot-intake-relay@doulapilot-prod.iam.gserviceaccount.com (unique ID 102235443082418518609). gcloud iap web get-iam-policy for the resource lists it with roles/iap.httpsResourceAccessor.
- A token minted for that account with that exact audience (decoded claims): aud = the client ID above, email = the service account address, email_verified = true, iss = https://accounts.google.com, sub = 102235443082418518609. Presented within its validity window, it is rejected with the audience error above.
- A token minted without the email claim is rejected earlier with "JWT 'email' claim isn't a string", confirming the audience failure occurs after the email stage, on a token whose aud demonstrably matches.
 

Question: what audience value does IAP expect for programmatic tokens to this Cloud Run resource, if not the client ID in its own redirect?

Best answer by Alex-Doulapilot

Resolved — by a different method than the one in my question. Posting the outcome in case it helps the next person.

The OIDC identity-token path against the Google-managed OAuth client never worked here, and I never got an explanation for why a token whose aud matches the client ID in IAP's own redirect is rejected on audience grounds. My IAP settings were empty/default throughout. One hypothesis is that the managed client isn't on any programmatic-clients allowlist — untested, because the alternative below worked immediately.

What works: a service account signed JWT, per the programmatic authentication docs. Claims: iss = sub = the service account email, aud = the EXACT URL being called (I used the full …/api/health URL), iat/exp as usual, signed via gcloud iam service-accounts sign-jwt (the IAM Credentials API is the same mechanism). The service account keeps its roles/iap.httpsResourceAccessor grant. Result: HTTP 200 from the application behind IAP, no IAP error header.

So if you're hitting "Invalid JWT audience" with generated identity tokens on a Cloud Run IAP resource using the managed client: try the signed-JWT method before rebuilding anything.

View original

3 replies

Alex-Doulapilot
Forum|alt.badge.img+2

Update (4 Dec 2026): since posting, we also tried fully re-provisioning IAP on the service — gcloud run services update doulapilot-admin --no-iap, then --iap again. It changed nothing: IAP came back with the same OAuth client ID, and a freshly minted token (aud = that client ID, email claim present and verified, accessor grant in place) is still rejected with "Invalid JWT audience." The IAP settings for the resource are empty/default — no custom OAuth config.


Alex-Doulapilot
Forum|alt.badge.img+2

Resolved — by a different method than the one in my question. Posting the outcome in case it helps the next person.

The OIDC identity-token path against the Google-managed OAuth client never worked here, and I never got an explanation for why a token whose aud matches the client ID in IAP's own redirect is rejected on audience grounds. My IAP settings were empty/default throughout. One hypothesis is that the managed client isn't on any programmatic-clients allowlist — untested, because the alternative below worked immediately.

What works: a service account signed JWT, per the programmatic authentication docs. Claims: iss = sub = the service account email, aud = the EXACT URL being called (I used the full …/api/health URL), iat/exp as usual, signed via gcloud iam service-accounts sign-jwt (the IAM Credentials API is the same mechanism). The service account keeps its roles/iap.httpsResourceAccessor grant. Result: HTTP 200 from the application behind IAP, no IAP error header.

So if you're hitting "Invalid JWT audience" with generated identity tokens on a Cloud Run IAP resource using the managed client: try the signed-JWT method before rebuilding anything.


ErikaB
Community Manager
Forum|alt.badge.img+13
  • Community Manager
  • Dec 4, 2026 8:41 PM UTC

Hi ​@Alex-Doulapilot 

 

Thank you for sharing your issue and detailed solution with the community!