Skip to content

Commit

Permalink
Merge pull request #576 from azmeuk/multiple-endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture authored Sep 13, 2023
2 parents 1807ba6 + cd32e15 commit e853408
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
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

0 comments on commit e853408

Please sign in to comment.