aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--djangorestframework/tests/authentication.py6
-rw-r--r--djangorestframework/tokenauth/authentication.py4
-rw-r--r--djangorestframework/tokenauth/models.py2
-rw-r--r--docs/api-guide/authentication.md2
4 files changed, 7 insertions, 7 deletions
diff --git a/djangorestframework/tests/authentication.py b/djangorestframework/tests/authentication.py
index da003a05..dfed2fcc 100644
--- a/djangorestframework/tests/authentication.py
+++ b/djangorestframework/tests/authentication.py
@@ -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)
diff --git a/djangorestframework/tokenauth/authentication.py b/djangorestframework/tokenauth/authentication.py
index 167edf96..327a4a09 100644
--- a/djangorestframework/tokenauth/authentication.py
+++ b/djangorestframework/tokenauth/authentication.py
@@ -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()
diff --git a/djangorestframework/tokenauth/models.py b/djangorestframework/tokenauth/models.py
index b5a9f7b9..81d98863 100644
--- a/djangorestframework/tokenauth/models.py
+++ b/djangorestframework/tokenauth/models.py
@@ -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.
"""
diff --git a/docs/api-guide/authentication.md b/docs/api-guide/authentication.md
index c5e4c1cc..c5b7ac9c 100644
--- a/docs/api-guide/authentication.md
+++ b/docs/api-guide/authentication.md
@@ -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.