Rename the default token class to "BasicToken"

This commit is contained in:
Mjumbe Wawatu Poe 2012-09-07 14:23:53 -04:00
parent 36cd91bbbe
commit 3b1404bd7d
4 changed files with 7 additions and 7 deletions

View File

@ -8,7 +8,7 @@ from django.http import HttpResponse
from djangorestframework.views import APIView
from djangorestframework import permissions
from djangorestframework.tokenauth.models import Token
from djangorestframework.tokenauth.models import BasicToken
from djangorestframework.tokenauth.authentication import TokenAuthentication
import base64
@ -123,7 +123,7 @@ class TokenAuthTests(TestCase):
self.user = User.objects.create_user(self.username, self.email, self.password)
self.key = 'abcd1234'
self.token = Token.objects.create(key=self.key, user=self.user)
self.token = BasicToken.objects.create(key=self.key, user=self.user)
def test_post_form_passing_token_auth(self):
"""Ensure POSTing json over token auth with correct credentials passes and does not require CSRF"""
@ -149,5 +149,5 @@ class TokenAuthTests(TestCase):
def test_token_has_auto_assigned_key_if_none_provided(self):
"""Ensure creating a token with no key will auto-assign a key"""
token = Token.objects.create(user=self.user)
token = BasicToken.objects.create(user=self.user)
self.assertEqual(len(token.key), 32)

View File

@ -1,5 +1,5 @@
from djangorestframework.authentication import BaseAuthentication
from .models import Token
from .models import BasicToken
class TokenAuthentication(BaseAuthentication):
"""
@ -20,7 +20,7 @@ class TokenAuthentication(BaseAuthentication):
Authorization: Token 0123456789abcdef0123456789abcdef
"""
model = Token
model = BasicToken
def authenticate(self, request):
auth = request.META.get('HTTP_AUTHORIZATION', '').strip().split()

View File

@ -18,7 +18,7 @@ class BaseToken(models.Model):
return super(BaseToken, self).save(*args, **kwargs)
class Token(BaseToken):
class BasicToken(BaseToken):
"""
The default authorization token model class.
"""

View File

@ -76,7 +76,7 @@ This policy uses [HTTP Authentication][basicauth] with a custom authentication s
If successfully authenticated, `TokenAuthentication` provides the following credentials.
* `request.user` will be a `django.contrib.auth.models.User` instance.
* `request.auth` will be a `djangorestframework.tokenauth.models.Token` instance.
* `request.auth` will be a `djangorestframework.tokenauth.models.BasicToken` instance.
To use the `TokenAuthentication` scheme, you must have a token model. Django REST Framework comes with a minimal default token model. To use it, include `djangorestframework.tokenauth` in your installed applications. To use your own token model, subclass the `djangorestframework.tokenauth.authentication.TokenAuthentication` class and specify a `model` attribute that references your custom token model. The token model must provide `user`, `key`, and `revoked` attributes. For convenience, the `djangorestframework.tokenauth.models.BaseToken` abstract model implements this minimum contract, and also randomly populates the key field when none is provided.