Skip to content

Commit 1bcfd5e

Browse files
committed
Provide django.contrib.auth.authenticate() with a request for
compatibiity with more backends. Resolves #712. Resolves #636. Resolves #808.
1 parent 5d53d24 commit 1bcfd5e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

oauth2_provider/oauth2_validators.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from django.core.exceptions import ObjectDoesNotExist
1515
from django.db import transaction
1616
from django.db.models import Q
17+
from django.http import HttpRequest
1718
from django.utils import dateformat, timezone
1819
from django.utils.timezone import make_aware
1920
from django.utils.translation import gettext_lazy as _
@@ -664,7 +665,18 @@ def validate_user(self, username, password, client, request, *args, **kwargs):
664665
"""
665666
Check username and password correspond to a valid and active User
666667
"""
667-
u = authenticate(username=username, password=password)
668+
# Passing the optional HttpRequest adds compatibility for backends
669+
# which depend on its presence. Create one with attributes likely
670+
# to be used.
671+
http_request = HttpRequest()
672+
http_request.path = request.uri
673+
http_request.method = request.http_method
674+
if request.http_method == "GET":
675+
http_request.GET.update(dict(request.decoded_body))
676+
elif request.http_method == "POST":
677+
http_request.POST.update(dict(request.decoded_body))
678+
http_request.META = request.headers
679+
u = authenticate(http_request, username=username, password=password)
668680
if u is not None and u.is_active:
669681
request.user = u
670682
return True

0 commit comments

Comments
 (0)