Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions .github/workflows/docs.yml

This file was deleted.

18 changes: 13 additions & 5 deletions castlecraft/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def validate():
"""
Additional validation to execute along with frappe request
"""
idp = get_enabled_idp()
idp_name = frappe.get_request_header("X-Idp-Name", "")
idp = get_idp(idp_name)
if not idp:
return

Expand Down Expand Up @@ -217,12 +218,19 @@ def validate_bearer_with_jwt_verification(token, idp):
)


def get_enabled_idp():
def get_idp(idp_name=None):
try:
if idp_name:
return frappe.get_cached_doc(
"CFE Identity Provider",
idp_name,
)

return frappe.get_last_doc(
"CFE Identity Provider",
filters={"enabled": 1},
)

except DoesNotExistError:
return None

Expand Down Expand Up @@ -290,7 +298,7 @@ def get_b64_decoded_json(b64str):


def validate_signature(token, idp=None):
idp = idp or get_enabled_idp()
idp = idp or get_idp()
allowed_audience = [audience.aud for audience in idp.allowed_audience]
r = requests.get(idp.jwks_endpoint)
jwks_keys = r.json()
Expand Down Expand Up @@ -369,7 +377,7 @@ def delete_cached_jwt(email: str):

def request_user_info(token, idp=None):
if not idp:
idp = get_enabled_idp()
idp = get_idp()
r = requests.get(
idp.profile_endpoint,
headers={"Authorization": f"Bearer {token}"},
Expand All @@ -379,7 +387,7 @@ def request_user_info(token, idp=None):

def get_userinfo_from_idp(token, idp=None):
if not idp:
idp = get_enabled_idp()
idp = get_idp()
if idp.authorization_type == "Introspection":
return request_user_info(token, idp)
elif idp.authorization_type == "JWT Verification":
Expand Down