Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set claim from token on Django user model #46

Closed
tschale opened this issue Feb 21, 2024 · 0 comments · Fixed by #47
Closed

Set claim from token on Django user model #46

tschale opened this issue Feb 21, 2024 · 0 comments · Fixed by #47
Assignees
Labels
enhancement New feature or request

Comments

@tschale
Copy link
Member

tschale commented Feb 21, 2024

We should enable pycloak to set claims from the token on the Django user model.

Let's take following example:

  • claim birthday
  • User model has a UserProfile, which has the field birth_day, i.e. user.profile.birth_day

We need a setting PYCLOAK_CLAIM_TO_USER_MAPPING, which maps the name of the claim to the field of the user. This needs to support nested related lookups, separated by dot-notation. Optionally a callback function can be specified, if the value needs parsing/processing.

Example:

from wherever import parse_birthday

PYCLOAK_CLAIM_TO_USER_MAPPING = {
    "birthday": {"field": "profile.birth_day", "callback": parse_birthday
}

We need a setting PYCLOAK_CLAIM_SKIP_MISSING. If this is True, pycloak skips when the claim is not present in the token and logs a warning. If this is False, pycloak will raise a django.core.exceptions.ImproperlyConfigured error.

We need a setting PYCLOAK_CLAIM_IGNORE_VALIDATION_ERRORS. If this is True, pycloak logs a warning when a validation error is raised. If this is False, pycloak will raise the exception.

The field on the user model is set in the middleware at 7. login user. We only need to set it, if we login the user or if it's the same user with a new token.

@tschale tschale self-assigned this Feb 21, 2024
@tschale tschale added the enhancement New feature or request label Feb 21, 2024
Schille added a commit that referenced this issue Feb 21, 2024
feat(#46): set claim from token on user model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant