fix: github api endpoint
This commit is contained in:
parent
91f446ef04
commit
f3f01d1978
4 changed files with 19 additions and 2 deletions
|
|
@ -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"] = {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
11
frappe/patches/v14_0/update_github_endpoints.py
Normal file
11
frappe/patches/v14_0/update_github_endpoints.py
Normal file
|
|
@ -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"
|
||||
})
|
||||
)
|
||||
|
|
@ -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()))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue