Skip to content
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

Adding auto-gen email fallback for github oauth #1798

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1831,6 +1831,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 @@ -1895,12 +1896,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
Loading