Enable token authentication for the API, add API token request view
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from .classes import APIEndPoint
|
||||
from .urls import api_urls
|
||||
|
||||
endpoint = APIEndPoint('rest_api')
|
||||
endpoint.register_urls(api_urls)
|
||||
endpoint.add_endpoint('auth_token_obtain', _(u'Obtain an API authentication token.'))
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import absolute_import
|
||||
|
||||
from django.conf.urls import include, patterns, url
|
||||
|
||||
from .views import APIBase, Version_0, APIAppView
|
||||
from .views import APIBase, Version_0, APIAppView, BrowseableObtainAuthToken
|
||||
|
||||
version_0_urlpatterns = patterns('',
|
||||
url(r'^$', Version_0.as_view(), name='api-version-0'),
|
||||
@@ -13,3 +13,7 @@ urlpatterns = patterns('',
|
||||
url(r'^$', APIBase.as_view(), name='api-root'),
|
||||
url(r'^v0/', include(version_0_urlpatterns)),
|
||||
)
|
||||
|
||||
api_urls = patterns('',
|
||||
url(r'^auth/token/obtain/', BrowseableObtainAuthToken.as_view(), name='auth_token_obtain'),
|
||||
)
|
||||
|
||||
@@ -3,7 +3,8 @@ from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
|
||||
from rest_framework import generics
|
||||
from rest_framework import generics, renderers
|
||||
from rest_framework.authtoken.views import ObtainAuthToken
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
@@ -66,3 +67,10 @@ class APIAppView(generics.GenericAPIView):
|
||||
return Response({
|
||||
'endpoints': result
|
||||
})
|
||||
|
||||
|
||||
class BrowseableObtainAuthToken(ObtainAuthToken):
|
||||
"""
|
||||
Obtain an API authentication token.
|
||||
"""
|
||||
renderer_classes = (renderers.JSONRenderer, renderers.BrowsableAPIRenderer)
|
||||
|
||||
@@ -52,6 +52,7 @@ INSTALLED_APPS = (
|
||||
'mptt',
|
||||
'compressor',
|
||||
'rest_framework',
|
||||
'rest_framework.authtoken',
|
||||
'solo',
|
||||
# Base generic
|
||||
'permissions',
|
||||
@@ -255,6 +256,7 @@ REST_FRAMEWORK = {
|
||||
'MAX_PAGINATE_BY': 100,
|
||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||
'rest_framework.authentication.BasicAuthentication',
|
||||
'rest_framework.authentication.TokenAuthentication',
|
||||
'rest_framework.authentication.SessionAuthentication',
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user