Skip to content

Commit 6155ce0

Browse files
committed
Merge branch 'issue-1305-json-auth-endpoint' of github.com:jhnbyrn/django-oauth-toolkit into issue-1305-json-auth-endpoint
2 parents 701bacb + 29a084d commit 6155ce0

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

oauth2_provider/urls.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
base_urlpatterns = [
1010
re_path(r"^authorize/$", views.AuthorizationView.as_view(), name="authorize"),
11-
re_path(r"authorize.json/$", views.AuthorizationJSONView.as_view(),
12-
name="authorize-json"),
11+
re_path(r"authorize.json/$", views.AuthorizationJSONView.as_view(), name="authorize-json"),
1312
re_path(r"^token/$", views.TokenView.as_view(), name="token"),
1413
re_path(r"^revoke_token/$", views.RevokeTokenView.as_view(), name="revoke-token"),
1514
re_path(r"^introspect/$", views.IntrospectTokenView.as_view(), name="introspect"),

oauth2_provider/views/base.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
from django.contrib.auth.mixins import LoginRequiredMixin
66
from django.contrib.auth.views import redirect_to_login
7+
from django.core.serializers.json import DjangoJSONEncoder
8+
from django.db.models import Model
9+
10+
# JB
11+
from django.forms import model_to_dict
712
from django.http import HttpResponse
813
from django.shortcuts import resolve_url
914
from django.utils import timezone
@@ -12,11 +17,6 @@
1217
from django.views.decorators.debug import sensitive_post_parameters
1318
from django.views.generic import FormView, View
1419

15-
# JB
16-
from django.forms import model_to_dict
17-
from django.core.serializers.json import DjangoJSONEncoder
18-
from django.db.models import Model
19-
2020
from ..exceptions import OAuthToolkitError
2121
from ..forms import AllowForm
2222
from ..http import OAuth2ResponseRedirect
@@ -70,6 +70,7 @@ def redirect(self, redirect_to, application):
7070

7171
RFC3339 = "%Y-%m-%dT%H:%M:%SZ"
7272

73+
7374
class AuthorizationMixin:
7475
def get_context(self, request, *args, **kwargs):
7576
try:
@@ -145,12 +146,11 @@ def get_context(self, request, *args, **kwargs):
145146
return self.error_response(error, application)
146147
return kwargs
147148

149+
148150
class AuthorizationJSONView(BaseAuthorizationView, AuthorizationMixin):
149151
def get(self, request, *args, **kwargs):
150152
context = self.get_context(request, *args, **kwargs)
151-
return HttpResponse(
152-
content=json.dumps(context, cls=self.ExtendedEncoder),
153-
status=200)
153+
return HttpResponse(content=json.dumps(context, cls=self.ExtendedEncoder), status=200)
154154

155155
def post(self, request, *args, **kwargs):
156156
body = request.POST
@@ -183,14 +183,15 @@ def post(self, request, *args, **kwargs):
183183
self.success_url = uri
184184
log.debug("Success url for the request: {0}".format(self.success_url))
185185
return self.redirect(self.success_url, application)
186-
186+
187187
class ExtendedEncoder(DjangoJSONEncoder):
188188
def default(self, o):
189189
if isinstance(o, Model):
190190
return model_to_dict(o)
191191
else:
192192
return super().default(o)
193193

194+
194195
class AuthorizationView(BaseAuthorizationView, FormView, AuthorizationMixin):
195196
"""
196197
Implements an endpoint to handle *Authorization Requests* as in :rfc:`4.1.1` and prompting the

0 commit comments

Comments
 (0)