RealmTeam / django-rest-framework-social-oauth2

python-social-auth and oauth2 support for django-rest-framework
MIT License
1.06k stars 191 forks source link

Question: Return JWT for user instead of tokens #124

Closed kinesii closed 7 years ago

kinesii commented 7 years ago

How would I go about returning a JWT instead of a token to my frontend?

I can manually create a JWT like so (with the rest_framework_jwt module):

from rest_framework_jwt.settings import api_settings
jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER

def manual_create_JWT(user):
    """ Generate JWT token for user and pass back to client. Requires the user to be authenticated.  """
    payload = jwt_payload_handler(user)
    return jwt_encode_handler(payload)
PhilipGarnero commented 7 years ago

We use django-oauth-toolkit as our token generator. You should check over there the progress on token customizations.