From f2391ee3706bd6b3a93e505d509abdabe651163b Mon Sep 17 00:00:00 2001 From: Rasool Safari Date: Thu, 23 Aug 2018 20:51:24 +0430 Subject: [PATCH] Add docs for manual token creation --- README.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.rst b/README.rst index ef83d90cc..d37bd9f6d 100644 --- a/README.rst +++ b/README.rst @@ -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 -----------