diff --git a/mayan/apps/rest_api/__init__.py b/mayan/apps/rest_api/__init__.py index e69de29bb2..3b434cfaea 100644 --- a/mayan/apps/rest_api/__init__.py +++ b/mayan/apps/rest_api/__init__.py @@ -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.')) diff --git a/mayan/apps/rest_api/urls.py b/mayan/apps/rest_api/urls.py index 2e22f0d559..f9a5d0352a 100644 --- a/mayan/apps/rest_api/urls.py +++ b/mayan/apps/rest_api/urls.py @@ -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'), +) diff --git a/mayan/apps/rest_api/views.py b/mayan/apps/rest_api/views.py index 759b3be228..7eafb19488 100644 --- a/mayan/apps/rest_api/views.py +++ b/mayan/apps/rest_api/views.py @@ -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) diff --git a/mayan/settings/base.py b/mayan/settings/base.py index 12f5e0a5dd..9fcedb67d0 100644 --- a/mayan/settings/base.py +++ b/mayan/settings/base.py @@ -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', ) }