Relax oauthlib scope check for Google group enrollment#712
Merged
Conversation
Google commonly grants additional scopes we didn't request (openid, userinfo.email, userinfo.profile) alongside the ones we did. oauthlib treats any scope mismatch as fatal by default, raising `Warning: Scope has changed from "..." to "..."` from flow.fetch_token() — this propagated up through handle_redirect() and got caught by the generic exception handler in oauth_integrations/views.py, turning an otherwise-successful authorization into a 400. Set OAUTHLIB_RELAX_TOKEN_SCOPE=1 before fetch_token() so oauthlib doesn't reject a superset of the requested scopes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
tests/oauth_integrations/test_google_group_enrollment_handler.py imports requests and exercises the real google_auth_oauthlib.flow.Flow to verify the OAUTHLIB_RELAX_TOKEN_SCOPE fix end-to-end, but google-auth-oauthlib was only declared under the optional "google" extra, not the dev dependency group CI installs via `make dev-install` (poetry install --with dev). CI failed to even collect the test module as a result. Add it to dev, matching how openai is already there for the "ai" extra. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an OAuth redirect failure reported from production logs:
```
{"levelname": "ERROR", "name": "django_email_learning.oauth_integrations.views", "message": "Error processing OAuth redirect: Scope has changed from "https://www.googleapis.com/auth/admin.directory.user.readonly https://www.googleapis.com/auth/admin.directory.group.readonly\" to "https://www.googleapis.com/auth/admin.directory.group.readonly https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/admin.directory.user.readonly https://www.googleapis.com/auth/userinfo.email openid"."}
Bad Request: /email_learning/oauth/redirect/