Commit 3b1404bd by Mjumbe Wawatu Poe

Rename the default token class to "BasicToken"

parent 36cd91bb
...@@ -8,7 +8,7 @@ from django.http import HttpResponse ...@@ -8,7 +8,7 @@ from django.http import HttpResponse
from djangorestframework.views import APIView from djangorestframework.views import APIView
from djangorestframework import permissions from djangorestframework import permissions
from djangorestframework.tokenauth.models import Token from djangorestframework.tokenauth.models import BasicToken
from djangorestframework.tokenauth.authentication import TokenAuthentication from djangorestframework.tokenauth.authentication import TokenAuthentication
import base64 import base64
...@@ -123,7 +123,7 @@ class TokenAuthTests(TestCase): ...@@ -123,7 +123,7 @@ class TokenAuthTests(TestCase):
self.user = User.objects.create_user(self.username, self.email, self.password) self.user = User.objects.create_user(self.username, self.email, self.password)
self.key = 'abcd1234' 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): def test_post_form_passing_token_auth(self):
"""Ensure POSTing json over token auth with correct credentials passes and does not require CSRF""" """Ensure POSTing json over token auth with correct credentials passes and does not require CSRF"""
...@@ -149,5 +149,5 @@ class TokenAuthTests(TestCase): ...@@ -149,5 +149,5 @@ class TokenAuthTests(TestCase):
def test_token_has_auto_assigned_key_if_none_provided(self): def test_token_has_auto_assigned_key_if_none_provided(self):
"""Ensure creating a token with no key will auto-assign a key""" """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) self.assertEqual(len(token.key), 32)
from djangorestframework.authentication import BaseAuthentication from djangorestframework.authentication import BaseAuthentication
from .models import Token from .models import BasicToken
class TokenAuthentication(BaseAuthentication): class TokenAuthentication(BaseAuthentication):
""" """
...@@ -20,7 +20,7 @@ class TokenAuthentication(BaseAuthentication): ...@@ -20,7 +20,7 @@ class TokenAuthentication(BaseAuthentication):
Authorization: Token 0123456789abcdef0123456789abcdef Authorization: Token 0123456789abcdef0123456789abcdef
""" """
model = Token model = BasicToken
def authenticate(self, request): def authenticate(self, request):
auth = request.META.get('HTTP_AUTHORIZATION', '').strip().split() auth = request.META.get('HTTP_AUTHORIZATION', '').strip().split()
......
...@@ -18,7 +18,7 @@ class BaseToken(models.Model): ...@@ -18,7 +18,7 @@ class BaseToken(models.Model):
return super(BaseToken, self).save(*args, **kwargs) return super(BaseToken, self).save(*args, **kwargs)
class Token(BaseToken): class BasicToken(BaseToken):
""" """
The default authorization token model class. The default authorization token model class.
""" """
......
...@@ -76,7 +76,7 @@ This policy uses [HTTP Authentication][basicauth] with a custom authentication s ...@@ -76,7 +76,7 @@ This policy uses [HTTP Authentication][basicauth] with a custom authentication s
If successfully authenticated, `TokenAuthentication` provides the following credentials. If successfully authenticated, `TokenAuthentication` provides the following credentials.
* `request.user` will be a `django.contrib.auth.models.User` instance. * `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. 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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment