-
Notifications
You must be signed in to change notification settings - Fork 24
fix(oauth): conditionally set client_id based on auth method #2968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Move client_id setting from generic request setup to auth-method-specific handlers. This ensures client_id is only included when using client assertion authentication, not for all request types.
Summary of ChangesHello @imdominicreed, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the handling of the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Client ID now waits, Only when assertion calls, Auth flow is precise. Footnotes
|
There was a problem hiding this 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 correctly refactors the OAuth client authentication logic to conditionally include the client_id parameter based on the authentication method. The changes ensure client_id is only sent in the request body for client assertion authentication, which aligns with OAuth 2.0 standards.
While the changes for the client_credentials grant in getAccessTokenRequest are implemented correctly, the modification in getCertExchangeRequest exposes a latent critical bug. The request body is constructed before the client authentication parameters are added, which will cause authentication to fail when using client assertions. I've provided a detailed comment with a suggested fix. Please note that getTokenExchangeRequest suffers from the same issue and should also be corrected.
|
|
||
| func getCertExchangeRequest(ctx context.Context, tokenEndpoint string, clientCredentials ClientCredentials, exchangeInfo CertExchangeInfo, key jwk.Key) (*http.Request, error) { | ||
| data := url.Values{"grant_type": {"password"}, "client_id": {clientCredentials.ClientID}, "username": {""}, "password": {""}} | ||
| data := url.Values{"grant_type": {"password"}, "username": {""}, "password": {""}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While removing the unconditional client_id here is correct, it reveals a critical logic bug in this function's order of operations.
The request body is created from data on line 342, but setClientAuth—which should conditionally add client_id for client assertion authentication—is called on line 355, after the body has been created. This means any modifications setClientAuth makes to the data map will not be included in the request body, breaking client assertion authentication.
To fix this, this function should be refactored to follow the pattern in getAccessTokenRequest:
- Create the
http.Requestwith anilbody. - Call
setClientAuthto populate headers and/or theurl.Valuesmap. - Encode the
url.Valuesand set thereq.Body.
A similar bug also exists in getTokenExchangeRequest and should be addressed.
Move client_id setting from generic request setup to auth-method-specific handlers. This ensures client_id is only included when using client assertion authentication, not for all request types.
Proposed Changes
Checklist
Testing Instructions