Skip to content

Commit

Permalink
Merge pull request #2301 from frappe/mergify/bp/version-15-hotfix/pr-…
Browse files Browse the repository at this point in the history
…2091
  • Loading branch information
krantheman authored Oct 18, 2024
2 parents 7bd1e10 + 5dcc21f commit 6781cf7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
22 changes: 21 additions & 1 deletion frontend/src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@
Login
</Button>
</form>

<template v-if="authProviders.data?.length">
<div class="text-center text-sm text-gray-600 my-4">or</div>
<div class="space-y-4">
<a
v-for="provider in authProviders.data"
:key="provider.name"
class="flex items-center justify-center gap-2 transition-colors focus:outline-none text-gray-800 bg-gray-100 hover:bg-gray-200 active:bg-gray-300 focus-visible:ring focus-visible:ring-gray-400 h-7 text-base p-2 rounded"
:href="provider.auth_url"
>
<img class="h-4 w-4" :src="provider.icon" :alt="provider.provider_name" />
<span>Login with {{ provider.provider_name }}</span>
</a>
</div>
</template>
</div>
</div>

Expand Down Expand Up @@ -88,7 +103,7 @@
<script setup>
import { IonPage, IonContent } from "@ionic/vue"
import { inject, reactive, ref } from "vue"
import { Input, Button, ErrorMessage, Dialog } from "frappe-ui"
import { Input, Button, ErrorMessage, Dialog, createResource } from "frappe-ui"
import FrappeHRLogo from "@/components/icons/FrappeHRLogo.vue"
Expand Down Expand Up @@ -141,4 +156,9 @@ async function submit(e) {
errorMessage.value = error.messages.join("\n")
}
}
const authProviders = createResource({
url: "hrms.api.oauth.oauth_providers",
auto: true,
})
</script>
33 changes: 33 additions & 0 deletions hrms/api/oauth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import frappe


@frappe.whitelist(allow_guest=True)
def oauth_providers():
from frappe.utils.html_utils import get_icon_html
from frappe.utils.oauth import get_oauth2_authorize_url, get_oauth_keys
from frappe.utils.password import get_decrypted_password

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

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, "/hrms"),
"icon": provider.icon,
}
)

return out
5 changes: 4 additions & 1 deletion hrms/www/hrms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ def get_context_for_dev():

def get_boot():
return frappe._dict(
{"site_name": frappe.local.site, "push_relay_server_url": frappe.conf.get("push_relay_server_url")}
{
"site_name": frappe.local.site,
"push_relay_server_url": frappe.conf.get("push_relay_server_url") or "",
}
)

0 comments on commit 6781cf7

Please sign in to comment.