Commit d907af3c authored by David Haynes's avatar David Haynes 🙆

PoC with using tokens for API request

- woo
parent 31a70dee
Pipeline #2983 passed with stage
in 56 seconds
......@@ -13,7 +13,12 @@ class GolinksList extends React.Component {
componentDidMount() {
if (window.django.user.is_authenticated == "True") {
fetch("/api/golinks")
fetch("/api/golinks/", {
headers: {
"Content-Type": "application/json; charset=utf-8",
Authorization: "Token {props.token}"
}
})
.then(res => res.json())
.then(
result => {
......
......@@ -28,6 +28,7 @@ from .models import URL, RegisteredUser
from django.contrib.auth.models import User, Group
from rest_framework import viewsets
from rest_framework import permissions
from rest_framework.authentication import TokenAuthentication
from .serializers import URLSerializer
class URLPermission(permissions.BasePermission):
......@@ -42,6 +43,7 @@ class URLViewSet(viewsets.ModelViewSet):
"""
API endpoint that handles creation/read/update/deletion of URL objects.
"""
authentication_classes = (TokenAuthentication, )
serializer_class = URLSerializer
permission_classes = (URLPermission,)
lookup_field = 'short'
......
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