Skip to content

Commit d2f5b60

Browse files
committed
fix(oauth): remove redundant client_id from token exchange request body
Authlib's OAuth2Session already handles client_id placement for all token_endpoint_auth_method values (client_secret_basic puts it in the Authorization header, client_secret_post and none put it in the body). Passing client_id as a kwarg to fetch_token causes it to be added to the POST body unconditionally via prepare_token_request, in addition to whatever the auth method does. This breaks providers like Slack that infer auth method from the presence of client_id in the body, and causes duplicate client_id for client_secret_post. Partially reverts f273517 (PR #2805), which was based on a misreading of RFC 6749 §4.1.3 — client_id in the body is only REQUIRED "if the client is not authenticating with the authorization server as described in Section 3.2.1." Made-with: Cursor
1 parent ffe97ec commit d2f5b60

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/google/adk/auth/exchanger/oauth2_credential_exchanger.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,17 @@ async def _exchange_authorization_code(
193193
return ExchangeResult(auth_credential, False)
194194

195195
try:
196+
# Do not pass client_id here; the OAuth2Session already handles its
197+
# placement based on token_endpoint_auth_method (e.g. in the
198+
# Authorization header for client_secret_basic, or in the body for
199+
# client_secret_post and public clients).
196200
tokens = client.fetch_token(
197201
token_endpoint,
198202
authorization_response=self._normalize_auth_uri(
199203
auth_credential.oauth2.auth_response_uri
200204
),
201205
code=auth_credential.oauth2.auth_code,
202206
grant_type=OAuthGrantType.AUTHORIZATION_CODE,
203-
client_id=auth_credential.oauth2.client_id,
204207
)
205208
update_credential_with_tokens(auth_credential, tokens)
206209
logger.debug("Successfully exchanged authorization code for access token")

tests/unittests/auth/exchanger/test_oauth2_credential_exchanger.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ async def test_exchange_normalize_uri(self, mock_oauth2_session):
343343
authorization_response="https://example.com/callback?code=auth_code", # Normalized URI
344344
code="auth_code",
345345
grant_type=OAuthGrantType.AUTHORIZATION_CODE,
346-
client_id="test_client_id",
347346
)
348347

349348
async def test_determine_grant_type_client_credentials(self):

0 commit comments

Comments
 (0)