Statistics
| Branch: | Tag: | Revision:

root / api / authentication.py @ b016b476

History | View | Annotate | Download (875 Bytes)

1
# vim: ts=4 sts=4 et ai sw=4 fileencoding=utf-8
2
#
3
# Copyright © 2010 Greek Research and Technology Network
4
#
5

    
6
from django.contrib.auth.models import User, AnonymousUser
7
from synnefo.api.faults import fault
8

    
9
# XXX: we need to add a Vary X-Auth-Token, somehow
10
# XXX: or use a standard auth middleware instead?
11
#      but watch out for CSRF issues:
12
#      http://andrew.io/weblog/2010/01/django-piston-and-handling-csrf-tokens/
13

    
14
class TokenAuthentication(object):
15
    def is_authenticated(self, request):
16
        request.user = User()
17
        return True
18
        token = request.META.get('HTTP_X_AUTH_TOKEN', None)
19
        if not token:
20
            return False
21

    
22
        # XXX: lookup token in models and set request.user
23
        if token:
24
            request.user = AnonymousUser()
25
            return True
26

    
27
    def challenge(self):
28
        return fault.unauthorized.response
29