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 { ...@@ -13,7 +13,12 @@ class GolinksList extends React.Component {
componentDidMount() { componentDidMount() {
if (window.django.user.is_authenticated == "True") { 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(res => res.json())
.then( .then(
result => { result => {
......
...@@ -28,6 +28,7 @@ from .models import URL, RegisteredUser ...@@ -28,6 +28,7 @@ from .models import URL, RegisteredUser
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from rest_framework import viewsets from rest_framework import viewsets
from rest_framework import permissions from rest_framework import permissions
from rest_framework.authentication import TokenAuthentication
from .serializers import URLSerializer from .serializers import URLSerializer
class URLPermission(permissions.BasePermission): class URLPermission(permissions.BasePermission):
...@@ -42,6 +43,7 @@ class URLViewSet(viewsets.ModelViewSet): ...@@ -42,6 +43,7 @@ class URLViewSet(viewsets.ModelViewSet):
""" """
API endpoint that handles creation/read/update/deletion of URL objects. API endpoint that handles creation/read/update/deletion of URL objects.
""" """
authentication_classes = (TokenAuthentication, )
serializer_class = URLSerializer serializer_class = URLSerializer
permission_classes = (URLPermission,) permission_classes = (URLPermission,)
lookup_field = 'short' 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