Skip to content

impl(oauth2): add methods for returning multiple auth related http headers#16064

Open
scotthart wants to merge 1 commit intogoogleapis:mainfrom
scotthart:rab_minimal_iam
Open

impl(oauth2): add methods for returning multiple auth related http headers#16064
scotthart wants to merge 1 commit intogoogleapis:mainfrom
scotthart:rab_minimal_iam

Conversation

@scotthart
Copy link
Copy Markdown
Member

This PR adds methods for retrieving the authorization and x-allowed-locations headers individually, as well as, the AuthenticationHeaders method as a single place to get all the auth related headers for RPC calls.

Copy link
Copy Markdown

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

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 refactors the credential authentication system to support multiple HTTP headers, replacing the single AuthenticationHeader with a vector-based AuthenticationHeaders method and adding specific logic for Authorization and AllowedLocations. A review comment suggests that errors from AllowedLocations should be handled more explicitly—either by logging or propagation—to avoid sending requests with missing headers that might cause ambiguous service failures.

auto allowed_locations = AllowedLocations(tp, endpoint);
// Not all credential types support the x-allowed-locations header. For those
// that do, if there is a problem retrieving the header, omit the header.
if (allowed_locations.ok() && !allowed_locations->empty()) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The current implementation silently ignores any errors returned by AllowedLocations. While the comment suggests this is intentional for credential types that don't support it, an actual Status error (other than OK) from an implementation that does attempt to provide it might indicate a transient failure (e.g., metadata server timeout). Swallowing such errors could lead to requests being sent without required headers, potentially causing confusing 403 or 400 errors from the service. Consider if specific error codes should be propagated or at least logged.

References
  1. Prefer defensive code, such as explicit ok() checks, even if they seem redundant based on the current implementation of a framework, as the framework's contract may change in the future.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.69%. Comparing base (fdbec33) to head (e64f424).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16064      +/-   ##
==========================================
- Coverage   92.70%   92.69%   -0.01%     
==========================================
  Files        2343     2343              
  Lines      216644   216664      +20     
==========================================
+ Hits       200838   200846       +8     
- Misses      15806    15818      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant