mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-30 18:27:45 -05:00
use django authentication instead of auth tokens.
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
from rest_framework.authentication import TokenAuthentication
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from rest_framework import authentication
|
||||
|
||||
|
||||
class AngularApiAuthenticationOverride(authentication.BaseAuthentication):
|
||||
""" This class is here to provide authentication to the angular dev server
|
||||
during development. This is disabled in production.
|
||||
"""
|
||||
|
||||
# This authentication method is required to serve documents and thumbnails for the front end.
|
||||
# https://stackoverflow.com/questions/29433416/token-in-query-string-with-django-rest-frameworks-tokenauthentication
|
||||
class QueryTokenAuthentication(TokenAuthentication):
|
||||
def authenticate(self, request):
|
||||
# Check if 'token_auth' is in the request query params.
|
||||
if 'auth_token' in request.query_params and 'HTTP_AUTHORIZATION' not in request.META:
|
||||
return self.authenticate_credentials(request.query_params.get('auth_token'))
|
||||
if settings.DEBUG and 'Origin' in request.headers and request.headers['Origin'] == 'http://localhost:4200':
|
||||
user = User.objects.filter(is_staff=True).first()
|
||||
print("Auto-Login with user {}".format(user))
|
||||
return (user, None)
|
||||
else:
|
||||
return None
|
||||
|
Reference in New Issue
Block a user