Allow token and session auth

This commit is contained in:
2021-04-05 20:48:14 -05:00
parent 0793242dfe
commit b46ec965e1
3 changed files with 12 additions and 5 deletions

View File

@@ -4,4 +4,4 @@ from bookmarks.models import Bookmark
class BookmarkSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Bookmark
fields = ['title', 'url']
fields = ['title', 'url', 'id']

View File

@@ -1,5 +1,6 @@
from django.urls import include, path
from rest_framework import routers
from rest_framework import routers, authtoken
from rest_framework.authtoken import views as authtokenviews
from . import views
router = routers.DefaultRouter()
@@ -9,5 +10,6 @@ router.register(r'bookmarks', views.BookmarkViewSet, basename='bookmark')
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
path('', include(router.urls)),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
path('token/', authtokenviews.obtain_auth_token),
]

View File

@@ -40,6 +40,7 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken'
]
MIDDLEWARE = [
@@ -128,8 +129,12 @@ REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
'rest_framework.permissions.IsAuthenticated'
],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 100
'PAGE_SIZE': 100,
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
]
}