All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 31s
22 lines
921 B
Python
22 lines
921 B
Python
from rest_framework.authentication import SessionAuthentication, BaseAuthentication
|
|
from django.contrib.auth.models import User
|
|
from .models import SupplierProfile
|
|
|
|
class CsrfExemptSessionAuthentication(SessionAuthentication):
|
|
def enforce_csrf(self, request):
|
|
return
|
|
|
|
class DummyAuthentication(BaseAuthentication):
|
|
def authenticate(self, request):
|
|
auth_header = request.headers.get('Authorization', '')
|
|
if auth_header.startswith('Bearer '):
|
|
# Defer to JWT authentication when an explicit token is provided
|
|
return None
|
|
user = User.objects.first()
|
|
if not user:
|
|
user = User.objects.create_user(username='dummy', email='dummy@example.com', password='password')
|
|
SupplierProfile.objects.create(user=user)
|
|
elif not hasattr(user, 'profile'):
|
|
SupplierProfile.objects.create(user=user)
|
|
return (user, None)
|
|
|