File: rest_framework_auth.py

package info (click to toggle)
django-webtest 1.9.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 268 kB
  • sloc: python: 1,115; sh: 16; makefile: 8
file content (16 lines) | stat: -rw-r--r-- 492 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from django.contrib.auth import authenticate

from rest_framework import authentication


class WebtestAuthentication(authentication.BaseAuthentication):
    """Bridge between webtest and django-rest-framework."""

    header = 'WEBTEST_USER'

    def authenticate(self, request):
        value = request.META.get(self.header)
        if value:
            account = authenticate(django_webtest_user=value)
            if account and account.is_active:
                return (account, None)