Skip to content

Commit

Permalink
Add validations and default values
Browse files Browse the repository at this point in the history
Throw readable exception if the user does not have an email address.

Do not fail if the user does not belong to any group.
  • Loading branch information
MohammedNoureldin authored Jun 14, 2024
1 parent 41c7461 commit d3de0a0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions oidc_extended/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@ def custom(code: str, state: str | dict):

id_token = jwt.decode(token_response["id_token"], audience="erpnext", options={"verify_signature": False})
username = id_token[user_id_claim_name]
email = id_token[email_claim_name]

if email_claim_name in id_token:
email = id_token[email_claim_name]
else:
frappe.msgprint("The user must have an email address.", raise_exception=True)

first_name = id_token.get(given_name_claim_name, "No first name")
last_name = id_token.get(family_name_claim_name, "No last name")
# The groups the user have as received in the token.
groups = id_token[groups_claim_name]
groups = id_token.get(groups_claim_name, "")
frappe.logger().debug(f"Groups of user {username}: {groups}")

# Creates the user if does not exsit, otherwise updates the data according to the claims of the token.
Expand Down

0 comments on commit d3de0a0

Please sign in to comment.