fix: public info api
This commit is contained in:
parent
49e084868b
commit
88d8c1e56a
4 changed files with 7 additions and 5 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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()))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue