Skip to content

Commit

Permalink
Merge pull request #1796 from SciPhi-AI/feature/add-gh-oauth-logic
Browse files Browse the repository at this point in the history
add logic for github auth
  • Loading branch information
emrgnt-cmplxty authored Jan 10, 2025
2 parents 47828e2 + 810a6f3 commit 4a77ebf
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions py/core/providers/auth/r2r_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,14 +612,32 @@ async def oauth_callback_handler(
email=email
or f"{oauth_id}@google_oauth.fake", # fallback
password=None, # no password
account_type="google",
account_type="oauth",
google_id=oauth_id,
)
)
elif provider == "github":
# Similar approach for GitHub
# ...
pass
try:
user = await self.database_provider.users_handler.get_user_by_email(
email
)
# If user found, check if user.google_id matches or is null. If null, update it
if user and not user.github_id:
raise R2RException(
status_code=401,
message="User already exists and is not linked to Github account",
)
except:
# Create new user
user = (
await self.database_provider.users_handler.create_user(
email=email
or f"{oauth_id}@github_oauth.fake", # fallback
password=None, # no password
account_type="oauth",
github_id=oauth_id,
)
)
# else handle other providers

except R2RException:
Expand Down

0 comments on commit 4a77ebf

Please sign in to comment.