1
# Python
2 6
import logging
3

4
# Django
5 6
from django.utils.encoding import smart_text
6

7
# Django REST Framework
8 6
from rest_framework import authentication
9

10 6
logger = logging.getLogger('cyborgbackup.api.authentication')
11

12

13 6
class LoggedBasicAuthentication(authentication.BasicAuthentication):
14

15 6
    def authenticate(self, request):
16 6
        ret = super(LoggedBasicAuthentication, self).authenticate(request)
17 6
        if ret:
18 0
            username = ret[0].username if ret[0] else '<none>'
19 0
            logger.debug(smart_text(u"User {} performed a {} to {} through the API".format(username,
20
                                                                                           request.method,
21
                                                                                           request.path)))
22 6
        return ret
23

24 6
    def authenticate_header(self, request):
25 6
        return super(LoggedBasicAuthentication, self).authenticate_header(request)
26

27

28 6
class SessionAuthentication(authentication.SessionAuthentication):
29

30 6
    def authenticate_header(self, request):
31 6
        return 'Session'
32

33 6
    def enforce_csrf(self, request):
34 6
        return None

Read our documentation on viewing source code .

Loading