Skip to content

Commit 9d2aac2

Browse files
ShaheedHaquen2ygk
andauthored
Provide django.contrib.auth.authenticate() with a request for compatibiity with more backends. (#949)
* Provide django.contrib.auth.authenticate() with a request for compatibiity with more backends. Resolves #712. Resolves #636. Resolves #808. Co-authored-by: Alan Crosswell <[email protected]>
1 parent 39a4577 commit 9d2aac2

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ Rustem Saiargaliev
5050
Jadiel Teófilo
5151
pySilver
5252
Łukasz Skarżyński
53+
Shaheed Haque

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
### Security
1515
-->
1616

17-
## [1.5.0] 2021-03-18
17+
## [unreleased]
1818

1919
### Added
20-
* #915 Add optional OpenID Connect support.
20+
* #712, #636, #808. Calls to `django.contrib.auth.authenticate()` now pass a `request`
21+
to provide compatibility with backends that need one.
22+
2123
### Fixed
2224
* #524 Restrict usage of timezone aware expire dates to Django projects with USE_TZ set to True.
2325

26+
## [1.5.0] 2021-03-18
27+
28+
### Added
29+
* #915 Add optional OpenID Connect support.
30+
2431
### Changed
2532
* #942 Help via defunct Google group replaced with using GitHub issues
2633

oauth2_provider/oauth2_validators.py

Lines changed: 10 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,15 @@ 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+
getattr(http_request, request.http_method).update(dict(request.decoded_body))
675+
http_request.META = request.headers
676+
u = authenticate(http_request, username=username, password=password)
668677
if u is not None and u.is_active:
669678
request.user = u
670679
return True

0 commit comments

Comments
 (0)