Skip to content
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

register several endpoints of a kind #576

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions authlib/common/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ def __call__(self, uri=None):
body = dict(self.get_body())
headers = self.get_headers()
return self.status_code, body, headers


class ContinueIteration(AuthlibBaseError):
pass
19 changes: 12 additions & 7 deletions authlib/oauth2/rfc6749/authorization_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from authlib.common.errors import ContinueIteration
from .authenticate_client import ClientAuthentication
from .requests import OAuth2Request, JsonRequest
from .errors import (
Expand Down Expand Up @@ -186,7 +187,8 @@ def register_endpoint(self, endpoint_cls):
:param endpoint_cls: A endpoint class
"""
self._endpoints[endpoint_cls.ENDPOINT_NAME] = endpoint_cls(self)
endpoints = self._endpoints.setdefault(endpoint_cls.ENDPOINT_NAME, [])
endpoints.append(endpoint_cls(self))

def get_authorization_grant(self, request):
"""Find the authorization grant for current request.
Expand Down Expand Up @@ -231,12 +233,15 @@ def create_endpoint_response(self, name, request=None):
if name not in self._endpoints:
raise RuntimeError(f'There is no "{name}" endpoint.')

endpoint = self._endpoints[name]
request = endpoint.create_endpoint_request(request)
try:
return self.handle_response(*endpoint(request))
except OAuth2Error as error:
return self.handle_error_response(request, error)
endpoints = self._endpoints[name]
for endpoint in endpoints:
request = endpoint.create_endpoint_request(request)
try:
return self.handle_response(*endpoint(request))
except ContinueIteration:
continue
except OAuth2Error as error:
return self.handle_error_response(request, error)

def create_authorization_response(self, request=None, grant_user=None):
"""Validate authorization request and create authorization response.
Expand Down
Loading