Skip to content

fix(auth): send configured scopes in the OAuth2 client-credentials exchange - #8389

Open
sumedh-aerram wants to merge 2 commits into
google:mainfrom
sumedh-aerram:fix/oauth2-client-credentials-scopes
Open

sumedh-aerram wants to merge 2 commits into
google:mainfrom
sumedh-aerram:fix/oauth2-client-credentials-scopes

Conversation

@sumedh-aerram

Copy link
Copy Markdown

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Fixes #8388

2. Description of change:

Problem: Configured OAuth2 client-credentials scopes are omitted from the token POST. This grant has no authorization redirect to carry them, so providers can return default permissions or reject the request.

Solution: Pass the space-joined configured scope keys to fetch_token only for client credentials, including configured OpenID Connect scopes. Empty scopes remain absent. Authorization-code exchange and refresh retain their existing scope omission.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

python -m pytest -q -p no:cacheprovider tests/unittests/auth: 373 passed, 127 warnings on Python 3.11.

Before the fix, the targeted regression/control selection produced 4 failed, 2 passed, 14 deselected. Six real-Authlib wire-body cases cover OAuth2 and OpenID Connect with empty, single, and multiple scopes. The existing authorization-code exchange and refresh scope-omission controls also pass.

Pre-commit passed on every changed file. Mypy passes on the changed production files; explicitly checking changed test files produces the same 31 existing diagnostics as the original files, with zero new errors.

Manual End-to-End (E2E) Tests:

Run the offline reproducer from the linked issue using real Authlib and a mocked requests transport. The POST now contains scope=['read:items'] and the exchange succeeds.

Offline reproduction was executed with corrected expectations after the fix. Live-provider/service end-to-end testing was not performed.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end against a live service.

Additional context

This preserves the scope-omission behavior for refresh and authorization-code exchange established by #5328 / #5874.

…change

Pass the configured OAuth2 or OpenID Connect scopes only when fetching a client-credentials token. Keep authorization-code exchange and refresh scope omission unchanged.

Fixes google#8388
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.

OAuth2 client-credentials exchange ignores configured scopes

1 participant