diff options
| author | Tom Christie | 2013-06-29 21:02:58 +0100 | 
|---|---|---|
| committer | Tom Christie | 2013-06-29 21:02:58 +0100 | 
| commit | 664f8c63655770cd90bdbd510b315bcd045b380a (patch) | |
| tree | 2145a39de36701bc67cad67f2b303594a76d23e9 /rest_framework/request.py | |
| parent | 35022ca9213939a2f40c82facffa908a818efe0b (diff) | |
| download | django-rest-framework-664f8c63655770cd90bdbd510b315bcd045b380a.tar.bz2 | |
Added APIClient.authenticate()
Diffstat (limited to 'rest_framework/request.py')
| -rw-r--r-- | rest_framework/request.py | 20 | 
1 files changed, 20 insertions, 0 deletions
| diff --git a/rest_framework/request.py b/rest_framework/request.py index 0d88ebc7..919716f4 100644 --- a/rest_framework/request.py +++ b/rest_framework/request.py @@ -64,6 +64,20 @@ def clone_request(request, method):      return ret +class ForcedAuthentication(object): +    """ +    This authentication class is used if the test client or request factory +    forcibly authenticated the request. +    """ + +    def __init__(self, force_user, force_token): +        self.force_user = force_user +        self.force_token = force_token + +    def authenticate(self, request): +        return (self.force_user, self.force_token) + +  class Request(object):      """      Wrapper allowing to enhance a standard `HttpRequest` instance. @@ -98,6 +112,12 @@ class Request(object):          self.parser_context['request'] = self          self.parser_context['encoding'] = request.encoding or settings.DEFAULT_CHARSET +        force_user = getattr(request, '_force_auth_user', None) +        force_token = getattr(request, '_force_auth_token', None) +        if (force_user is not None or force_token is not None): +            forced_auth = ForcedAuthentication(force_user, force_token) +            self.authenticators = (forced_auth,) +      def _default_negotiator(self):          return api_settings.DEFAULT_CONTENT_NEGOTIATION_CLASS() | 
