Skip to content

Commit 110b73f

Browse files
committed
compat with LoginRequiredMiddleware and login_not_required
1 parent dc3d8ff commit 110b73f

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

oauth2_provider/compat.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,11 @@
22
The `compat` module provides support for backwards compatibility with older
33
versions of Django and Python.
44
"""
5+
try:
6+
# Django 5.1 introduced LoginRequiredMiddleware, and login_not_required decorator
7+
from django.contrib.auth.decorators import login_not_required
8+
except ImportError:
9+
def login_not_required(view_func):
10+
return view_func
11+
12+
__all__ = ['login_not_required']

oauth2_provider/views/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from django.views.decorators.debug import sensitive_post_parameters
1414
from django.views.generic import FormView, View
1515

16+
from ..compat import login_not_required
1617
from ..exceptions import OAuthToolkitError
1718
from ..forms import AllowForm
1819
from ..http import OAuth2ResponseRedirect
@@ -274,6 +275,7 @@ def handle_no_permission(self):
274275

275276

276277
@method_decorator(csrf_exempt, name="dispatch")
278+
@method_decorator(login_not_required, name="dispatch")
277279
class TokenView(OAuthLibMixin, View):
278280
"""
279281
Implements an endpoint to provide access tokens
@@ -301,6 +303,7 @@ def post(self, request, *args, **kwargs):
301303

302304

303305
@method_decorator(csrf_exempt, name="dispatch")
306+
@method_decorator(login_not_required, name="dispatch")
304307
class RevokeTokenView(OAuthLibMixin, View):
305308
"""
306309
Implements an endpoint to revoke access or refresh tokens

oauth2_provider/views/oidc.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from jwcrypto.jwt import JWTExpired
1515
from oauthlib.common import add_params_to_uri
1616

17+
from ..compat import login_not_required
1718
from ..exceptions import (
1819
ClientIdMissmatch,
1920
InvalidIDTokenError,
@@ -38,7 +39,7 @@
3839

3940
Application = get_application_model()
4041

41-
42+
@method_decorator(login_not_required, name="dispatch")
4243
class ConnectDiscoveryInfoView(OIDCOnlyMixin, View):
4344
"""
4445
View used to show oidc provider configuration information per
@@ -105,7 +106,7 @@ def get(self, request, *args, **kwargs):
105106
response["Access-Control-Allow-Origin"] = "*"
106107
return response
107108

108-
109+
@method_decorator(login_not_required, name="dispatch")
109110
class JwksInfoView(OIDCOnlyMixin, View):
110111
"""
111112
View used to show oidc json web key set document
@@ -134,6 +135,7 @@ def get(self, request, *args, **kwargs):
134135

135136

136137
@method_decorator(csrf_exempt, name="dispatch")
138+
@method_decorator(login_not_required, name="dispatch")
137139
class UserInfoView(OIDCOnlyMixin, OAuthLibMixin, View):
138140
"""
139141
View used to show Claims about the authenticated End-User
@@ -210,7 +212,7 @@ def _validate_claims(request, claims):
210212

211213
return True
212214

213-
215+
@method_decorator(login_not_required, name="dispatch")
214216
class RPInitiatedLogoutView(OIDCLogoutOnlyMixin, FormView):
215217
template_name = "oauth2_provider/logout_confirm.html"
216218
form_class = ConfirmLogoutForm

0 commit comments

Comments
 (0)