Fixed an issue where OAuth2 authentication fails with 'object has no attribute' if OAUTH2_AUTO_CREATE_USER is False. #9279#9691
Conversation
…attribute' if OAUTH2_AUTO_CREATE_USER is False. pgadmin-org#9279
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughReplaced hard-coded strings with gettext-wrapped messages across the OAuth2 authentication flow and claim validation. Modified __auto_create_user to check for an existing user before creating; if not found and auto-creation is disabled, return a localized failure message. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@web/pgadmin/authenticate/oauth2.py`:
- Around line 699-700: The failure message returned by the "return False,
gettext(...)" line in oauth2.py is misleading for the branch where the user
isn't provisioned and auto-create is disabled; update that gettext string to
clearly state that the user exists in the identity provider but is not
provisioned in pgAdmin and automatic user creation is disabled (e.g., "User not
provisioned in pgAdmin and automatic user creation is disabled. Please contact
your administrator."), keeping it wrapped in gettext to preserve localization
and leaving the return tuple signature intact.
- Around line 710-712: The current check uses additional_claims.keys() is None
which is unreachable and causes empty dicts to be treated as failing; change the
logic to treat None or empty mappings as "no checks" and authorize: replace the
condition with a truthiness check (e.g., if not additional_claims:) and return
success (True, None) so an empty {} does not cause unauthorized; remove the
keys() is None check and ensure the rest of the additional_claims validation
only runs when additional_claims is non-empty.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b0245443-03fe-4cb3-9428-dda69e9bbcda
📒 Files selected for processing (1)
web/pgadmin/authenticate/oauth2.py
| return False, gettext('No Email/Username found.' | ||
| ' Please contact your administrator.') |
There was a problem hiding this comment.
Failure message is inaccurate for this branch.
This branch means “user not provisioned and auto-create disabled,” not “no email/username found,” which can mislead admins during triage.
Suggested message tweak
- return False, gettext('No Email/Username found.'
- ' Please contact your administrator.')
+ return False, gettext(
+ 'User is not provisioned in pgAdmin and automatic '
+ 'user creation is disabled. Please contact your '
+ 'administrator.'
+ )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@web/pgadmin/authenticate/oauth2.py` around lines 699 - 700, The failure
message returned by the "return False, gettext(...)" line in oauth2.py is
misleading for the branch where the user isn't provisioned and auto-create is
disabled; update that gettext string to clearly state that the user exists in
the identity provider but is not provisioned in pgAdmin and automatic user
creation is disabled (e.g., "User not provisioned in pgAdmin and automatic user
creation is disabled. Please contact your administrator."), keeping it wrapped
in gettext to preserve localization and leaving the return tuple signature
intact.
Summary by CodeRabbit
Localization
Bug Fixes