Get token:
curl -X POST -H "Content-Type: application/json" -d '{"username": "john", "password": "password"}' http://localhost:8080/api-token-auth/
Request:
curl -X GET -H "Authorization: Token <token>" http://localhost:8080/users/33456/ | json_pp
In Django urls.py add:
from rest_framework.authtoken.views import obtain_auth_token
urlpatterns = [
path('api-token-auth/', obtain_auth_token),
]
settings.py:
INSTALLED_APPS = [
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
]
REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE': 100,
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAdminUser',
),
}