1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-04 13:15:24 +00:00

moved jwt authentication to api app

This commit is contained in:
Bram Wiepjes 2019-06-24 20:50:30 +02:00
parent ee2b1e76d3
commit c1ae99f27d
10 changed files with 48 additions and 11 deletions
backend/src/baserow

View file

View file

@ -0,0 +1 @@
app_name = 'baserow.api.v0'

View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class ApiConfig(AppConfig):
name = 'baserow.api.v0'

View file

@ -0,0 +1,8 @@
from .serializers.user import UserSerializer
def jwt_response_payload_handler(token, user=None, request=None):
return {
'token': token,
'data': UserSerializer(user, context={'request': request}).data
}

View file

@ -0,0 +1,10 @@
from rest_framework import serializers
from django.contrib.auth import get_user_model
User = get_user_model()
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'first_name', 'username')

View file

@ -0,0 +1,18 @@
from django.urls import path, include
from django.conf.urls import url
from rest_framework import routers
from rest_framework_jwt.views import (
obtain_jwt_token, refresh_jwt_token, verify_jwt_token
)
app_name = 'baserow.api.v0'
router = routers.DefaultRouter()
urlpatterns = [
url(r'^token-auth/', obtain_jwt_token),
url(r'^token-refresh/', refresh_jwt_token),
url(r'^token-verify/', verify_jwt_token),
path('', include(router.urls)),
]

View file

@ -23,7 +23,9 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'rest_framework',
'corsheaders'
'corsheaders',
'baserow.api.v0'
]
MIDDLEWARE = [
@ -130,4 +132,5 @@ JWT_AUTH = {
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=300),
'JWT_ALLOW_REFRESH': True,
'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
'JWT_RESPONSE_PAYLOAD_HANDLER': 'baserow.api.v0.jwt.jwt_response_payload_handler'
}

View file

@ -1,15 +1,7 @@
from django.urls import path, include
from django.urls import include
from django.conf.urls import url
from rest_framework import routers
from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token
router = routers.DefaultRouter()
urlpatterns = [
url(r'^api/token-auth/', obtain_jwt_token),
url(r'^api/token-refresh/', refresh_jwt_token),
path('api/', include(router.urls)),
url(r'^api/', include('baserow.api.v0.urls', namespace='api')),
]