jpadilla / django-rest-framework-jwt

JSON Web Token Authentication support for Django REST Framework
http://jpadilla.github.io/django-rest-framework-jwt/
MIT License
3.19k stars 649 forks source link

could i add other information to payload? #367

Closed vparenti closed 6 years ago

vparenti commented 7 years ago

I would like add more information in payload json, for example 'role' and 'company'. Is there a way? Thanks, V

MauScheff commented 6 years ago

+1

Alex3917 commented 6 years ago

You just make a custom payload handler, e.g.:

from rest_framework_jwt.utils import jwt_payload_handler

def jwt_custom_payload_handler(user):
    payload = jwt_payload_handler(user)
    payload['role'] = 'xyz'
    return payload

Then in your settings you just need:

JWT_AUTH['JWT_PAYLOAD_HANDLER'] = 'path.to.your.jwt_custom_payload_handler'

blueyed commented 6 years ago

Could we add this to the docs then? @vparenti / @mauzepeda a PR would be welcome.

blueyed commented 6 years ago

Closing in favor of https://github.com/GetBlimp/django-rest-framework-jwt/pull/389 already. Thanks, @mauzepeda!