Disable auto-login with token requests
This commit is contained in:
parent
151d337f6c
commit
c5606024b3
@ -2,12 +2,16 @@ from django.conf import settings
|
|||||||
from django.contrib import auth
|
from django.contrib import auth
|
||||||
from django.contrib.auth.middleware import PersistentRemoteUserMiddleware
|
from django.contrib.auth.middleware import PersistentRemoteUserMiddleware
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.http import HttpRequest
|
||||||
from django.utils.deprecation import MiddlewareMixin
|
from django.utils.deprecation import MiddlewareMixin
|
||||||
from rest_framework import authentication
|
from rest_framework import authentication
|
||||||
|
|
||||||
|
|
||||||
class AutoLoginMiddleware(MiddlewareMixin):
|
class AutoLoginMiddleware(MiddlewareMixin):
|
||||||
def process_request(self, request):
|
def process_request(self, request: HttpRequest):
|
||||||
|
# Dont use auto-login with token request
|
||||||
|
if request.path.startswith("/api/token/") and request.method == "POST":
|
||||||
|
return None
|
||||||
try:
|
try:
|
||||||
request.user = User.objects.get(username=settings.AUTO_LOGIN_USERNAME)
|
request.user = User.objects.get(username=settings.AUTO_LOGIN_USERNAME)
|
||||||
auth.login(
|
auth.login(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user