refactor: fetch openID config in backend (#33586)

This commit is contained in:
Hussain Nagaria 2025-08-11 12:48:23 +05:30 committed by GitHub
parent 73b7a8424a
commit 89da9934bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 16 deletions

View file

@ -4,21 +4,16 @@
frappe.ui.form.on("Connected App", {
refresh: (frm) => {
frm.add_custom_button(__("Get OpenID Configuration"), async () => {
if (!frm.doc.openid_configuration) {
frappe.msgprint(__("Please enter OpenID Configuration URL"));
} else {
try {
const response = await fetch(frm.doc.openid_configuration);
const oidc = await response.json();
frm.set_value("authorization_uri", oidc.authorization_endpoint);
frm.set_value("token_uri", oidc.token_endpoint);
frm.set_value("userinfo_uri", oidc.userinfo_endpoint);
frm.set_value("introspection_uri", oidc.introspection_endpoint);
frm.set_value("revocation_uri", oidc.revocation_endpoint);
} catch (error) {
frappe.msgprint(__("Please check OpenID Configuration URL"));
}
}
frm.call("get_openid_configuration").then(({ message: oidc }) => {
frm.set_value("authorization_uri", oidc.authorization_endpoint);
frm.set_value("token_uri", oidc.token_endpoint);
frm.set_value("userinfo_uri", oidc.userinfo_endpoint);
frm.set_value("introspection_uri", oidc.introspection_endpoint);
frm.set_value("revocation_uri", oidc.revocation_endpoint);
frm.fields_dict.authorization_uri.section.collapse(false); // Un-collapse
frappe.show_alert(__("OpenID Configuration fetched successfully!"));
});
});
if (!frm.is_new()) {
@ -26,7 +21,7 @@ frappe.ui.form.on("Connected App", {
frappe.call({
method: "initiate_web_application_flow",
doc: frm.doc,
callback: function (r) {
callback: (r) => {
window.open(r.message, "_blank");
},
});

View file

@ -9,6 +9,7 @@ from requests_oauthlib import OAuth2Session
import frappe
from frappe import _
from frappe.integrations.utils import make_get_request
from frappe.model.document import Document
if any((os.getenv("CI"), frappe.conf.developer_mode, frappe.conf.allow_tests)):
@ -47,6 +48,12 @@ class ConnectedApp(Document):
in a Token Cache.
"""
@frappe.whitelist()
def get_openid_configuration(self):
if not self.openid_configuration:
frappe.throw(_("Please enter OpenID Configuration URL"))
return make_get_request(self.openid_configuration)
def validate(self):
base_url = frappe.utils.get_url()
callback_path = (