-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix OAuth w/ ext_perm_user for multi-tenant #4723
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
PR Summary
This PR modifies the OAuth user authentication flow in backend/onyx/auth/users.py
to better handle multi-tenant scenarios by improving session user matching and error handling.
- Removed redundant null checks after user creation in OAuth flow, simplifying error propagation
- Added session user matching logic to reuse existing authenticated users when email/OAuth credentials match
- Removed explicit HTTP 500 error responses in favor of letting exceptions propagate naturally
- Streamlined user creation and OAuth account linking to handle multi-tenant scenarios more gracefully
1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile
user = await self.user_db.create(user_dict) | ||
|
||
# Add OAuth account only if user creation was successful | ||
if user is not None: |
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.
user is never None
) | ||
|
||
# Ensure user is not None before proceeding | ||
if user is None: |
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.
user is never None
async with AsyncSession(engine, expire_on_commit=False) as async_session: | ||
# set the search path on sync session as well to be extra safe | ||
async_session.info["tenant_id"] = tenant_id | ||
event.listen( |
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.
seemingly the search_path gets reset after every commit on the async session?
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.
not 100% sure, but that's what I was observing
* Fix OAuth w/ ext_perm_user for multi-tenant * Improve comment
* Fix OAuth w/ ext_perm_user for multi-tenant * Improve comment
* Fix OAuth w/ ext_perm_user for multi-tenant * Improve comment
* Fix OAuth w/ ext_perm_user for multi-tenant * Improve comment
Description
Fixes https://linear.app/danswer/issue/DAN-1981/fix-oauth-with-ext-perm-user-on-cloud
How Has This Been Tested?
Tested w/ multi-tenant set up locally.
Backporting (check the box to trigger backport action)
Note: You have to check that the action passes, otherwise resolve the conflicts manually and tag the patches.