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 d6f55e5758..92bdacde72 100644 --- a/frappe/integrations/doctype/social_login_key/social_login_key.py +++ b/frappe/integrations/doctype/social_login_key/social_login_key.py @@ -78,9 +78,11 @@ 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", + "api_endpoint":"user/emails", "api_endpoint_args":None, - "auth_url_data":None + "auth_url_data": json.dumps({ + "scope": "user:email" + }) } providers["Google"] = { diff --git a/frappe/patches.txt b/frappe/patches.txt index c1b654d0e8..29dc4f77b7 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -184,3 +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 diff --git a/frappe/patches/v14_0/update_github_endpoints.py b/frappe/patches/v14_0/update_github_endpoints.py new file mode 100644 index 0000000000..b7ac67655e --- /dev/null +++ b/frappe/patches/v14_0/update_github_endpoints.py @@ -0,0 +1,11 @@ +import frappe +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 c28663d138..04d0cb1b1a 100644 --- a/frappe/utils/oauth.py +++ b/frappe/utils/oauth.py @@ -140,6 +140,9 @@ def get_info_via_oauth(provider, code, decoder=None, id_token=False): 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") == True, info))[0] + if not (info.get("email_verified") or info.get("email")): frappe.throw(_("Email not verified with {0}").format(provider.title()))