-
Notifications
You must be signed in to change notification settings - Fork 818
Add an authorize endpoint that uses JSON instead of a Django template… #1306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8b76b0d
29a084d
701bacb
6155ce0
855296d
1bbbe49
514ff85
d0c03e5
78bd3e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -66,7 +66,83 @@ def redirect(self, redirect_to, application): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RFC3339 = "%Y-%m-%dT%H:%M:%SZ" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class AuthorizationView(BaseAuthorizationView, FormView): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class AuthorizationMixin: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_context(self, request, *args, **kwargs): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_context(self, request, *args, **kwargs): | |
| def get_context(self, request, *args, **kwargs): | |
| """ | |
| Process the OAuth2 authorization request and build the context for the authorization view. | |
| This method performs complex authorization logic, including validating the authorization request, | |
| handling special prompt parameters, checking for prior user consent, and preparing context data | |
| for the authorization form. | |
| Parameters: | |
| request (HttpRequest): The current HTTP request object. | |
| *args: Additional positional arguments. | |
| **kwargs: Additional keyword arguments used to build the context. | |
| Returns: | |
| dict: A context dictionary containing authorization data for rendering the authorization form, | |
| if user consent is required. | |
| HttpResponse: An HTTP response (such as a redirect or error response) if the authorization | |
| request is invalid, or if user consent can be skipped. | |
| Side Effects: | |
| Sets self.oauth2_data to the context dictionary if consent is required. | |
| Exceptions: | |
| OAuthToolkitError: Raised if the authorization request is invalid. In this case, an error | |
| response is returned. | |
| """ |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar error: 'an in-house applications' should be 'in-house applications' (remove 'an'). Also, there's a missing space after the arrow: 'applications->' should be 'applications ->'.
| # This is useful for in-house applications-> assume an in-house applications | |
| # This is useful for in-house applications -> assume in-house applications |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could potentially avoid iteration by filtering by your desired scopes (assuming the scopes var here is the required scopes of the view)
| .objects.filter( | |
| scopes_filter = { 'scopes__icontains': scope for scope in scopes } | |
| .objects.filter( | |
| user=request.user, | |
| application=kwargs["application"], | |
| expires__gt=timezone.now(), | |
| **scopes_filter | |
| ).first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the function return the context or response is awkard. It should just return the context.
let the exception throw and hoist the try/except to the get method, so the get method is returning the error_response
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The dual return type pattern (dict vs HttpResponse) from get_context() creates implicit behavior that's difficult to follow. Consider using a more explicit pattern, such as a tuple (should_render, data) or separate methods for validation vs. context preparation to make the control flow clearer.
| context = self.get_context(request, *args, **kwargs) | |
| if isinstance(context, dict): | |
| form = self.get_form(self.get_form_class()) | |
| context["form"] = form | |
| return self.render_to_response(self.get_context_data(**context)) | |
| else: | |
| return context | |
| should_render, data = self.get_context(request, *args, **kwargs) | |
| if should_render: | |
| form = self.get_form(self.get_form_class()) | |
| data["form"] = form | |
| return self.render_to_response(self.get_context_data(**data)) | |
| else: | |
| return data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename AuthorizationMixin to AuthorizationViewMixin.