|
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,24 +146,24 @@ 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 | # handle JSON post, sanitization etc. |
157 | 157 | pass |
158 | | - |
| 158 | + |
159 | 159 | class ExtendedEncoder(DjangoJSONEncoder): |
160 | 160 | def default(self, o): |
161 | 161 | if isinstance(o, Model): |
162 | 162 | return model_to_dict(o) |
163 | 163 | else: |
164 | 164 | return super().default(o) |
165 | 165 |
|
| 166 | + |
166 | 167 | class AuthorizationView(BaseAuthorizationView, FormView, AuthorizationMixin): |
167 | 168 | """ |
168 | 169 | Implements an endpoint to handle *Authorization Requests* as in :rfc:`4.1.1` and prompting the |
|
0 commit comments