Skip to content

Commit

Permalink
Merge pull request #1798 from SciPhi-AI/feature/add-gh-email-fallback
Browse files Browse the repository at this point in the history
Adding auto-gen email fallback for github oauth
  • Loading branch information
emrgnt-cmplxty authored Jan 10, 2025
2 parents 33541cc + bd861d2 commit 5810cb6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion py/core/main/api/v3/users_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,7 @@ async def google_callback(
# id_info will contain "sub", "email", etc.
google_id = id_info["sub"]
email = id_info.get("email")
email = email or f"{google_id}@google_oauth.fake"

# 3. Now call our R2RAuthProvider method that handles "oauth-based" user creation or login
token_response = await self.providers.auth.oauth_callback_handler(
Expand Down Expand Up @@ -1892,12 +1893,13 @@ async def github_callback(
"https://api.github.com/user",
headers={"Authorization": f"Bearer {access_token}"},
).json()

github_id = str(
user_info_resp["id"]
) # GitHub user ID is typically an integer
# fetch email (sometimes you need to call /user/emails endpoint if user sets email private)
email = user_info_resp.get("email")

email = email or f"{github_id}@github_oauth.fake"
# 3. Pass to your auth provider
token_response = await self.providers.auth.oauth_callback_handler(
provider="github",
Expand Down

0 comments on commit 5810cb6

Please sign in to comment.