Django REST Frameworkの認証・権限・リクエスト制限の実装手法
認証機構の実装
APIリクエストの認証処理を実装します。
from rest_framework.authentication import BaseAuthentication
from rest_framework.exceptions import AuthenticationFailed
from .models import UserToken
class ApiKeyAuth(BaseAuthentication):
def authenticate(self, request):
api_key = request.META.get('HTTP_X_API_KEY')
token ...
8月23日 04:30 投稿