Skip to content

Commit

Permalink
Add default __getattr__ behavior to models.TokenUser (#528)
Browse files Browse the repository at this point in the history
* Add default __getattr__ behavior to models.TokenUser to allow getting custom claims defined in serializers

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
oscarychen and pre-commit-ci[bot] committed Feb 6, 2022
1 parent 40a7cb1 commit dc42547
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rest_framework_simplejwt/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ def is_authenticated(self):

def get_username(self):
return self.username

def __getattr__(self, attr):
"""This acts as a backup attribute getter for custom claims defined in Token serializers."""
return self.token.get(attr, None)

0 comments on commit dc42547

Please sign in to comment.