Visitar URL original
fix(auth/google): expose sub and verified email claims for opaque access tokens by borkur · Pull Request #4224 · googleapis/mcp-toolbox · GitHub
Skip to content

fix(auth/google): expose sub and verified email claims for opaque access tokens - #4224

Open
borkur wants to merge 2 commits into
googleapis:mainfrom
borkur:fix/google-auth-opaque-token-claims
Open

borkur wants to merge 2 commits into
googleapis:mainfrom
borkur:fix/google-auth-opaque-token-claims

Conversation

@borkur

@borkur borkur commented Oct 6, 2026 •

Copy link
Copy Markdown

Description

In MCP Auth mode (mcpEnabled: true), the google authService validates opaque
Google access tokens (ya29...) through the tokeninfo endpoint. It only decoded
aud, azp and scope from the response, so the claims map handed to tools
contained just aud and scope. Authenticated parameters that read email or
sub (authServices: [{name: ..., field: email}]) therefore failed for opaque
tokens with:

provided parameters were invalid: error parsing authenticated parameter "user_id": no field named email in claims

Google ID tokens already work, because their full JWT payload is returned as
claims. This brings opaque tokens in line with that behavior.

Solution: decode sub, email and email_verified from the tokeninfo
response and add them to the claims map. email / email_verified are only
exposed when tokeninfo reports email_verified as "true", so an unverified
address can't be used to populate parameters that drive access decisions. As
with ID tokens, sub and email are only present when the token was granted
the openid / email scopes. No config or behavior changes for tokens that
carry no identity fields.

Impact: field: email / field: sub now work for opaque access tokens in
MCP Auth mode. No change for ID tokens, for the existing audience/scope
validation, or for non-MCP mode.

Testing

  • Added TestValidateMCPAuth_Opaque_Claims (verified email, unverified email,
    missing email_verified, no identity fields). It fails without the change and
    passes with it.
  • go test ./internal/auth/... ./internal/server/... and
    golangci-lint run ./internal/auth/... pass. Package coverage for
    internal/auth/google goes from 54.2% to 56.2%.
  • Verified manually against a local build with a real Google opaque access
    token: a tool with authServices: [{name: google-mcp, field: email}] now
    receives the caller's verified email.
  • I did not add an integration test: the existing TestGoogleOAuthValidation
    uses an ADC token, and exercising email end to end needs a token for a real
    user account with the email scope. Happy to add one if you can suggest a
    suitable credential for CI.

Docs: noted which claims are available for opaque tokens in
docs/en/documentation/configuration/authentication/google.md.

PR Checklist

  • Make sure you reviewed
    CONTRIBUTING.md
  • Make sure to open an issue as a
    bug/issue
    before writing your code! That way we can discuss the change, evaluate
    designs, and agree on the general idea
  • Ensure you have manually reviewed the entire diff before requesting a
    review
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involve a breaking change

Fixes #4049 🦕

@google-cla

google-cla Bot commented Oct 6, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for exposing identity claims (sub, email, and email_verified) when validating opaque access tokens (MCP Auth mode) via Google's tokeninfo endpoint. It updates the JSON unmarshalling to handle Google's stringified boolean for email_verified, exposes these claims conditionally, adds comprehensive unit tests, and updates the documentation accordingly. I have no feedback to provide as there are no review comments.

…ess tokens

In MCP auth mode the google authService validates opaque access tokens via
Google's tokeninfo endpoint, but only returned aud and scope as claims. As a
result authenticated parameters using field: email or field: sub could not be
resolved ("no field named email in claims").

Decode sub, email and email_verified from the tokeninfo response and add them
to the claims. email is only exposed when email_verified is "true".

Refs googleapis#4049
@borkur
borkur force-pushed the fix/google-auth-opaque-token-claims branch from a122e22 to 9ac2e68 Compare October 7, 2026 13:47
@borkur
borkur marked this pull request as ready for review October 8, 2026 08:37
@borkur
borkur requested a review from a team as a code owner October 8, 2026 08:37

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP Auth: google authService drops email/sub from tokeninfo claims for opaque access tokens, so authenticated parameters cannot resolve them

2 participants