Skip to content

Commit

Permalink
Add docs for manual token creation
Browse files Browse the repository at this point in the history
  • Loading branch information
rasooll authored and davesque committed Mar 8, 2019
1 parent 2083778 commit f2391ee
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,29 @@ for the view, which is in turn used to generate the view's access token.
As with the standard token views, you'll also need to include a url route to
your subclassed view.

Creating tokens manually
------------------------

Sometimes, you may wish to manually create a token for a user. This could be
done as follows:

.. code-block:: python
from rest_framework_simplejwt.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
representations of new refresh and access tokens for the given user. In
general, a token for any subclass of ``rest_framework_simplejwt.tokens.Token``
can be created in this way.

Token types
-----------

Expand Down

0 comments on commit f2391ee

Please sign in to comment.