I develop a web-service that through the web-API should be connected with third-party applications via pregenerated key.
My solution is to use @csrf_exempt
, but it seems to be very bad solution.
How to authenticate connected application via key?
Asked
Active
Viewed 62 times
1

IEVGEN
- 117
- 8
-
CSRF protection is unnecessary for an API. http://stackoverflow.com/questions/10741339/do-csrf-attack-worries-apply-to-apis – James Fenwick Jan 22 '16 at 16:07
1 Answers
0
You can use permissions.
You need to add this to settings:
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'app_name.path.MyPermissionClass',
)
}
And then create you permission class. As described here.
from rest_framework import permissions
class MyPermissionClass(permissions.BasePermission):
def has_permission(self, request, view):
if request.META.get('HTTP_SECRET_KEY', None) == 'your key':
return True
else:
return False

DevilPinky
- 558
- 3
- 13