44
55from django .contrib .auth .mixins import LoginRequiredMixin
66from django .http import HttpResponse , JsonResponse
7+ from django .shortcuts import render
8+ from django .urls import reverse
79from django .utils import timezone
810from django .utils .decorators import method_decorator
911from django .views .decorators .csrf import csrf_exempt
1012from django .views .decorators .debug import sensitive_post_parameters
1113from django .views .generic import FormView , View
12- from django .shortcuts import render
13- from django .urls import reverse
1414
1515from ..exceptions import OAuthToolkitError
1616from ..forms import AllowForm
2121from ..signals import app_authorized
2222from .mixins import OAuthLibMixin
2323
24+
2425log = logging .getLogger ("oauth2_provider" )
2526
2627
@@ -61,7 +62,9 @@ def redirect(self, redirect_to, application):
6162 allowed_schemes = application .get_allowed_schemes ()
6263 return OAuth2ResponseRedirect (redirect_to , allowed_schemes )
6364
64- RFC3339 = '%Y-%m-%dT%H:%M:%SZ'
65+
66+ RFC3339 = "%Y-%m-%dT%H:%M:%SZ"
67+
6568
6669class AuthorizationView (BaseAuthorizationView , FormView ):
6770 """
@@ -208,23 +211,22 @@ def get(self, request, *args, **kwargs):
208211
209212 return self .render_to_response (self .get_context_data (** kwargs ))
210213
211- def redirect (self , redirect_to , application ,
212- token = None ):
214+ def redirect (self , redirect_to , application , token = None ):
213215
214216 if not redirect_to .startswith ("urn:ietf:wg:oauth:2.0:oob" ):
215217 return super ().redirect (redirect_to , application )
216218
217219 parsed_redirect = urllib .parse .urlparse (redirect_to )
218- code = urllib .parse .parse_qs (parsed_redirect .query )[' code' ][0 ]
220+ code = urllib .parse .parse_qs (parsed_redirect .query )[" code" ][0 ]
219221
220- if redirect_to .startswith (' urn:ietf:wg:oauth:2.0:oob:auto' ):
222+ if redirect_to .startswith (" urn:ietf:wg:oauth:2.0:oob:auto" ):
221223
222224 response = {
223- ' access_token' : code ,
224- ' token_uri' : redirect_to ,
225- ' client_id' : application .client_id ,
226- ' client_secret' : application .client_secret ,
227- ' revoke_uri' : reverse (' oauth2_provider:revoke-token' ),
225+ " access_token" : code ,
226+ " token_uri" : redirect_to ,
227+ " client_id" : application .client_id ,
228+ " client_secret" : application .client_secret ,
229+ " revoke_uri" : reverse (" oauth2_provider:revoke-token" ),
228230 }
229231
230232 return JsonResponse (response )
@@ -234,10 +236,11 @@ def redirect(self, redirect_to, application,
234236 request = self .request ,
235237 template_name = "oauth2_provider/authorized-oob.html" ,
236238 context = {
237- ' code' : code ,
239+ " code" : code ,
238240 },
239241 )
240242
243+
241244@method_decorator (csrf_exempt , name = "dispatch" )
242245class TokenView (OAuthLibMixin , View ):
243246 """
0 commit comments