functional auth

This commit is contained in:
Jonathan Baecker 2020-01-29 17:39:57 +01:00
parent 32b869d7bd
commit a4dee262be
6 changed files with 57 additions and 8 deletions

View File

@ -1,4 +1,6 @@
# from django.shortcuts import render
import os
from django.conf import settings
from rest_framework.views import APIView
from rest_framework.response import Response
@ -6,11 +8,21 @@ from .utils import IniParser
class Config(APIView):
"""
read and write config from ffplayout engine
for reading, endpoint is: http://127.0.0.1:8000/api/config/?config
"""
def get(self, request, *args, **kwargs):
if 'config' in request.GET.dict():
parser = IniParser()
parser.read('/etc/ffplayout/ffplayout.conf')
if os.path.isfile(settings.FFPLAYOUT_CONFIG):
parser = IniParser()
parser.read(settings.FFPLAYOUT_CONFIG)
return Response(parser.as_dict())
return Response(parser.as_dict())
else:
return Response({
"success": False,
"error": "ffpayout engine config file not found!"})
else:
return Response({"success": False})

Binary file not shown.

View File

@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
from datetime import timedelta
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -25,7 +26,7 @@ SECRET_KEY = '---a-very-important-secret-key:-generate-it-new---'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']
# Application definition
@ -38,12 +39,14 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'api'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
@ -101,10 +104,32 @@ AUTH_PASSWORD_VALIDATORS = [
}
]
# REST API
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework.authentication.SessionAuthentication',
],
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_PAGINATION_CLASS': (
'rest_framework.pagination.LimitOffsetPagination',
),
'PAGE_SIZE': 50
}
CORS_ORIGIN_WHITELIST = (
'http://127.0.0.1:3000',
'http://127.0.0.1:8000',
'http://localhost:3000',
'http://localhost:8000'
)
# simple JWT auth settings
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5),
'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
}
@ -126,3 +151,6 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
# path to ffplayout engine config
FFPLAYOUT_CONFIG = '/etc/ffplayout/ffplayout.conf'

View File

@ -28,7 +28,12 @@ router = routers.DefaultRouter()
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include(router.urls)),
path('api/config/', views.Config.as_view()),
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
path('api-auth/', include(
'rest_framework.urls', namespace='rest_framework')),
path('auth/token/', TokenObtainPairView.as_view(),
name='token_obtain_pair'),
path('auth/token/refresh/', TokenRefreshView.as_view(),
name='token_refresh')
]

4
requirements-base.txt Normal file
View File

@ -0,0 +1,4 @@
Django<=3.1
django-cors-headers
djangorestframework
djangorestframework-simplejwt

View File

@ -1,5 +1,5 @@
asgiref==3.2.3
Django==3.0
Django==3.0.2
djangorestframework==3.11.0
djangorestframework-simplejwt==4.4.0
PyJWT==1.7.1