|
1 | | -subtitle: JWTTokenUserAuthentication backend |
2 | | -title: Experimental features |
3 | | ---- |
4 | 1 |
|
5 | | -The `JWTTokenUserAuthentication` backend\'s `authenticate` method does |
| 2 | +The `JWTTokenUserAuth` backend\'s `authenticate` method does |
6 | 3 | not perform a database lookup to obtain a user instance. Instead, it |
7 | 4 | returns a `ninja_jwt.models.TokenUser` instance which acts as a |
8 | 5 | stateless user object backed only by a validated token instead of a |
9 | 6 | record in a database. This can facilitate developing single sign-on |
10 | 7 | functionality between separately hosted Django apps which all share the |
11 | 8 | same token secret key. To use this feature, add the |
12 | | -`ninja_jwt.authentication.JWTTokenUserAuthentication` backend (instead |
13 | | -of the default `JWTAuthentication` backend) to the Django REST |
14 | | -Framework\'s `DEFAULT_AUTHENTICATION_CLASSES` config setting: |
| 9 | +`ninja_jwt.authentication.JWTTokenUserAuth` backend (instead |
| 10 | +of the default `JWTAuth` backend) to the Django Ninja Extra route definition |
15 | 11 |
|
16 | 12 | ```python |
17 | | -REST_FRAMEWORK = { |
18 | | - ... |
19 | | - 'DEFAULT_AUTHENTICATION_CLASSES': ( |
20 | | - ... |
21 | | - 'ninja_jwt.authentication.JWTTokenUserAuthentication', |
22 | | - ) |
23 | | - ... |
24 | | -} |
| 13 | +from ninja_extra import APIController, router, route |
| 14 | +from ninja_jwt.authentication import JWTTokenUserAuth |
| 15 | + |
| 16 | +@router('') |
| 17 | +class MyController(APIController): |
| 18 | + @route.get('/some-endpoint', auth=JWTTokenUserAuth()) |
| 19 | + def some_endpoint(self): |
| 20 | + pass |
| 21 | + |
25 | 22 | ``` |
0 commit comments