-
Notifications
You must be signed in to change notification settings - Fork 0
auth token
git pull cd rivnefish (заходимо в папку з проектом.) python manage.py shell Далі тупо копіюємо і вставляємо:
from django.contrib.auth.models import User from rest_framework.authtoken.models import Token
for user in User.objects.all(): Token.objects.get_or_create(user=user)
Далі заходимо в адмінку і бачимо, що для всіх користувачів згенеровані токени: http://api.rivnefish.com/admin/authtoken/token/
[12:24:42] Max Melnychuk: Як використовувати токен? при запиті http://api.rivnefish.com/markers/?format=json&token=7eeb7a212a8fe6a1d11ac9a.... питає логін і пароль
[12:33:54] Alex K: curl -X GET http://site.me/admin -H 'Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b'
[12:34:09] Alex K: For clients to authenticate, the token key should be included in the Authorization HTTP header. The key should be prefixed by the string literal "Token", with whitespace separating the two strings.
[13:10:57] Max Melnychuk: дякую
В конфігураційному файлі обовязково додати опцію, туди ж де й WSGIScriptAlias: WSGIPassAuthorization On