[Patchew-devel] [PATCH 3/3] rest: add rest_auth support

Paolo Bonzini pbonzini at redhat.com
Mon May 13 13:52:56 UTC 2019


This adds API endpoints /api/v1/users/{login,logout}/ that can be
used to obtain an authentication token.
---
 api/urls.py         | 4 ++++
 patchew/settings.py | 1 +
 requirements.txt    | 1 +
 3 files changed, 6 insertions(+)

diff --git a/api/urls.py b/api/urls.py
index f71a5e4..b1e259f 100644
--- a/api/urls.py
+++ b/api/urls.py
@@ -8,6 +8,8 @@
 # This work is licensed under the MIT License.  Please see the LICENSE file or
 # http://opensource.org/licenses/MIT.
 
+from rest_auth.views import LoginView, LogoutView
+
 from django.conf.urls import url, include
 from rest_framework.routers import DefaultRouter
 from rest_framework_nested.routers import NestedDefaultRouter
@@ -49,6 +51,8 @@ results_router.register('results', rest.SeriesResultsViewSet, base_name='results
 schema_view = get_schema_view(title='API schema')
 
 urlpatterns = _build_urls() + [
+    url(r'^v1/users/login/$', LoginView.as_view(), name='rest_login'),
+    url(r'^v1/users/logout/$', LogoutView.as_view(), name='rest_logout'),
     url(r"^v1/", include(router.urls)),
     url(r"^v1/", include(projects_router.urls)),
     url(r"^v1/", include(results_router.urls)),
diff --git a/patchew/settings.py b/patchew/settings.py
index dead744..4e10b44 100644
--- a/patchew/settings.py
+++ b/patchew/settings.py
@@ -46,6 +46,7 @@ INSTALLED_APPS = [
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
+    'rest_auth',
     'rest_framework',
     'rest_framework.authtoken',
 ]
diff --git a/requirements.txt b/requirements.txt
index 59c9480..a03dbe7 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -6,6 +6,7 @@ gunicorn>=19
 djangorestframework>=3.0.0
 jsonfield2 >= 3.0, < 4.0
 drf-nested-routers
+django-rest-auth>=0.9.0
 coreapi-cli
 pyyaml
 psycopg2
-- 
2.21.0




More information about the Patchew-devel mailing list