|
4 | 4 |
|
5 | 5 | from django.contrib.auth.mixins import LoginRequiredMixin |
6 | 6 | 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 |
7 | 12 | from django.http import HttpResponse |
8 | 13 | from django.shortcuts import resolve_url |
9 | 14 | from django.utils import timezone |
|
12 | 17 | from django.views.decorators.debug import sensitive_post_parameters |
13 | 18 | from django.views.generic import FormView, View |
14 | 19 |
|
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 | | - |
20 | 20 | from ..exceptions import OAuthToolkitError |
21 | 21 | from ..forms import AllowForm |
22 | 22 | from ..http import OAuth2ResponseRedirect |
@@ -70,6 +70,7 @@ def redirect(self, redirect_to, application): |
70 | 70 |
|
71 | 71 | RFC3339 = "%Y-%m-%dT%H:%M:%SZ" |
72 | 72 |
|
| 73 | + |
73 | 74 | class AuthorizationMixin: |
74 | 75 | def get_context(self, request, *args, **kwargs): |
75 | 76 | try: |
@@ -145,12 +146,11 @@ def get_context(self, request, *args, **kwargs): |
145 | 146 | return self.error_response(error, application) |
146 | 147 | return kwargs |
147 | 148 |
|
| 149 | + |
148 | 150 | class AuthorizationJSONView(BaseAuthorizationView, AuthorizationMixin): |
149 | 151 | def get(self, request, *args, **kwargs): |
150 | 152 | 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) |
154 | 154 |
|
155 | 155 | def post(self, request, *args, **kwargs): |
156 | 156 | body = request.POST |
@@ -183,14 +183,15 @@ def post(self, request, *args, **kwargs): |
183 | 183 | self.success_url = uri |
184 | 184 | log.debug("Success url for the request: {0}".format(self.success_url)) |
185 | 185 | return self.redirect(self.success_url, application) |
186 | | - |
| 186 | + |
187 | 187 | class ExtendedEncoder(DjangoJSONEncoder): |
188 | 188 | def default(self, o): |
189 | 189 | if isinstance(o, Model): |
190 | 190 | return model_to_dict(o) |
191 | 191 | else: |
192 | 192 | return super().default(o) |
193 | 193 |
|
| 194 | + |
194 | 195 | class AuthorizationView(BaseAuthorizationView, FormView, AuthorizationMixin): |
195 | 196 | """ |
196 | 197 | Implements an endpoint to handle *Authorization Requests* as in :rfc:`4.1.1` and prompting the |
|
0 commit comments