diff --git a/crm/api/auth.py b/crm/api/auth.py new file mode 100644 index 00000000..d485ccc1 --- /dev/null +++ b/crm/api/auth.py @@ -0,0 +1,38 @@ +import frappe + +@frappe.whitelist(allow_guest=True) +def oauth_providers(): + from frappe.utils.html_utils import get_icon_html + from frappe.utils.password import get_decrypted_password + from frappe.utils.oauth import get_oauth2_authorize_url, get_oauth_keys + + out = [] + providers = frappe.get_all( + "Social Login Key", + filters={"enable_social_login": 1}, + fields=["name", "client_id", "base_url", "provider_name", "icon"], + order_by="name", + ) + + for provider in providers: + client_secret = get_decrypted_password("Social Login Key", provider.name, "client_secret") + if not client_secret: + continue + + icon = None + if provider.icon: + if provider.provider_name == "Custom": + icon = get_icon_html(provider.icon, small=True) + else: + icon = f"{provider.provider_name}" + + if provider.client_id and provider.base_url and get_oauth_keys(provider.name): + out.append( + { + "name": provider.name, + "provider_name": provider.provider_name, + "auth_url": get_oauth2_authorize_url(provider.name, "/crm"), + "icon": icon, + } + ) + return out \ No newline at end of file diff --git a/frontend/src/pages/Login.vue b/frontend/src/pages/Login.vue index 556d7a3c..d750ec06 100644 --- a/frontend/src/pages/Login.vue +++ b/frontend/src/pages/Login.vue @@ -2,7 +2,12 @@