Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Commit 67cbcb1

Browse files
committed
Merge pull request #163 from Alex3917/manually_generate_tokens
Add documentation for manually generating auth tokens.
2 parents 8ce5cf4 + c1b32fa commit 67cbcb1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@ class JSONWebTokenAuthenticationQS(BaseJSONWebTokenAuthentication):
249249
```
250250
It is recommended to use `BaseJSONWebTokenAuthentication`, a new base class with no logic around parsing the HTTP headers.
251251

252+
## Creating a new token manually ##
253+
254+
Sometimes you may want to manually generate a token, for example to return a token to the user immediately after account creation. You can do this as follows:
255+
256+
`from rest_framework_jwt.settings import api_settings`
257+
258+
```python
259+
jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
260+
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
261+
262+
payload = jwt_payload_handler(user)
263+
token = jwt_encode_handler(payload)
264+
```
265+
252266
[jwt-auth-spec]: http://tools.ietf.org/html/draft-ietf-oauth-json-web-token
253267
[drf]: http://django-rest-framework.org/
254268
[jwt-video]: https://www.youtube.com/watch?v=825hodQ61bg

0 commit comments

Comments
 (0)