Skip to content

Conversation

Weves
Copy link
Contributor

@Weves Weves commented May 16, 2025

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.

  • This PR should be backported (make sure to check that the backport attempt succeeds)
  • [Optional] Override Linear Check

@Weves Weves requested a review from a team as a code owner May 16, 2025 19:41
Copy link

vercel bot commented May 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
internal-search ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 16, 2025 8:26pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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

@Weves Weves force-pushed the fix-oauth-on-cloud branch from fe39295 to 3ef05b8 Compare May 16, 2025 20:17
user = await self.user_db.create(user_dict)

# Add OAuth account only if user creation was successful
if user is not None:
Copy link
Contributor Author

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:
Copy link
Contributor Author

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(
Copy link
Contributor Author

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?

Copy link
Contributor Author

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

@Weves Weves enabled auto-merge May 16, 2025 20:26
@Weves Weves added this pull request to the merge queue May 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 16, 2025
@Weves Weves merged commit 01ca9dc into main May 16, 2025
11 checks passed
@Weves Weves deleted the fix-oauth-on-cloud branch May 16, 2025 21:44
ferdinandl007 pushed a commit to ferdinandl007/onyx that referenced this pull request May 19, 2025
* Fix OAuth w/ ext_perm_user for multi-tenant

* Improve comment
aronszanto pushed a commit to aronszanto/onyx that referenced this pull request May 27, 2025
* Fix OAuth w/ ext_perm_user for multi-tenant

* Improve comment
ZhipengHe pushed a commit to ZhipengHe/onyx that referenced this pull request Jun 6, 2025
* Fix OAuth w/ ext_perm_user for multi-tenant

* Improve comment
AnkitTukatek pushed a commit to TukaTek/onyx that referenced this pull request Sep 23, 2025
* Fix OAuth w/ ext_perm_user for multi-tenant

* Improve comment
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.

2 participants