Skip to content

Commit

Permalink
Update default setting TOKEN_CLAIM_USER_ATTRIBUTE_MAP
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarychen committed Aug 26, 2024
1 parent 38e767c commit 9395737
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
14 changes: 12 additions & 2 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,25 @@ web token refresh and web sign out. Defaults to `"/api/auth/web"`.
This is the field on the User model that is used as the username. Defaults to `"username"`.

### TOKEN_CLAIM_USER_ATTRIBUTE_MAP
A dictionary mapping token claims to corresponding User model attributes. Defaults to the following:
A dictionary mapping token claims to corresponding User model attributes. Defaults to the following which are part
of Django's default User model:
```python
{
"user_id": "id",
"username": "username",
"first_name": "first_name",
"last_name": "last_name",
"email": "email",
"is_staff": "is_staff",
"is_superuser": "is_superuser",
"last_login": "last_login",
"date_joined": "date_joined",
"is_active": "is_active",
}
```
See [Customizing token claims for user](../readme.md#customizing-token-claims-for-user).
If you changed any of these attributes in your Django user model, you will need to update this dictionary accordingly.

See also: [Customizing token claims for user](../readme.md#customizing-token-claims-for-user).

### TOKEN_USER_ENCODER_CLS
JSON encoder class used to serializing User attributes to JWT claims.
Expand Down
7 changes: 7 additions & 0 deletions ninja_simple_jwt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ class NinjaSimpleJwtSettingsDict(TypedDict):
"TOKEN_CLAIM_USER_ATTRIBUTE_MAP": {
"user_id": "id",
"username": "username",
"first_name": "first_name",
"last_name": "last_name",
"email": "email",
"is_staff": "is_staff",
"is_superuser": "is_superuser",
"last_login": "last_login",
"date_joined": "date_joined",
"is_active": "is_active",
},
"TOKEN_USER_ENCODER_CLS": "ninja_simple_jwt.jwt.json_encode.TokenUserEncoder",
}
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = django-ninja-simple-jwt
version = 0.6.0
version = 0.6.1
description = Simple JWT-based authentication using Django and Django-ninja
long_description = file: README.md
url = https://github.com/oscarychen/django-ninja-simple-jwt
Expand Down

0 comments on commit 9395737

Please sign in to comment.