Ninja JWT Manual Token Creation
Sometimes you may wish to manually create a token for a user. This can be done as follows:
from ninja_jwt.tokens import RefreshToken
def get_tokens_for_user(user):
refresh = RefreshToken.for_user(user)
return {
'refresh': str(refresh),
'access': str(refresh.access_token),
}
The above function get_tokens_for_user will return the serialized representation of a new refresh token and access token for the given user.
In general, tokens of any subclass of ninja_jwt.tokens.Token can be created this way.
Success
Continue to the next chapter Token Types.
本文总阅读量次
