diff --git a/frappe/integrations/doctype/social_login_key/social_login_key.py b/frappe/integrations/doctype/social_login_key/social_login_key.py index 92bdacde72..195d6800be 100644 --- a/frappe/integrations/doctype/social_login_key/social_login_key.py +++ b/frappe/integrations/doctype/social_login_key/social_login_key.py @@ -78,7 +78,7 @@ class SocialLoginKey(Document): "authorize_url":"https://github.com/login/oauth/authorize", "access_token_url":"https://github.com/login/oauth/access_token", "redirect_url":"/api/method/frappe.www.login.login_via_github", - "api_endpoint":"user/emails", + "api_endpoint":"user", "api_endpoint_args":None, "auth_url_data": json.dumps({ "scope": "user:email" diff --git a/frappe/patches.txt b/frappe/patches.txt index 29dc4f77b7..8309b2df57 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -184,4 +184,4 @@ frappe.patches.v13_0.update_notification_channel_if_empty frappe.patches.v14_0.drop_data_import_legacy frappe.patches.v14_0.rename_cancelled_documents frappe.patches.v14_0.update_workspace2 # 20.09.2021 -frappe.patches.v14_0.update_github_endpoints +frappe.patches.v14_0.update_github_endpoints #08-11-2021 diff --git a/frappe/patches/v14_0/update_github_endpoints.py b/frappe/patches/v14_0/update_github_endpoints.py index c3a9285a78..8f9a06a043 100644 --- a/frappe/patches/v14_0/update_github_endpoints.py +++ b/frappe/patches/v14_0/update_github_endpoints.py @@ -3,7 +3,6 @@ import json def execute(): if frappe.db.exists("Social Login Key", "github"): - frappe.db.set_value("Social Login Key", "github", "api_endpoint", "user/emails") frappe.db.set_value("Social Login Key", "github", "auth_url_data", json.dumps({ "scope": "user:email" diff --git a/frappe/utils/oauth.py b/frappe/utils/oauth.py index 68d62129bd..df2f5dca62 100644 --- a/frappe/utils/oauth.py +++ b/frappe/utils/oauth.py @@ -138,10 +138,13 @@ def get_info_via_oauth(provider, code, decoder=None, id_token=False): else: api_endpoint = oauth2_providers[provider].get("api_endpoint") api_endpoint_args = oauth2_providers[provider].get("api_endpoint_args") + info = session.get(api_endpoint, params=api_endpoint_args).json() - if provider == "github": - info = list(filter(lambda x: x.get("primary"), info))[0] + if provider == "github" and not info.get("email"): + emails = session.get("/user/emails", params=api_endpoint_args).json() + email_dict = list(filter(lambda x: x.get("primary"), emails))[0] + info["email"] = email_dict.get("email") if not (info.get("email_verified") or info.get("email")): frappe.throw(_("Email not verified with {0}").format(provider.title()))