Skip to content

Commit e853408

Browse files
authored
Merge pull request authlib#576 from azmeuk/multiple-endpoints
2 parents 1807ba6 + cd32e15 commit e853408

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

authlib/common/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ def __call__(self, uri=None):
5757
body = dict(self.get_body())
5858
headers = self.get_headers()
5959
return self.status_code, body, headers
60+
61+
62+
class ContinueIteration(AuthlibBaseError):
63+
pass

authlib/oauth2/rfc6749/authorization_server.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from authlib.common.errors import ContinueIteration
12
from .authenticate_client import ClientAuthentication
23
from .requests import OAuth2Request, JsonRequest
34
from .errors import (
@@ -186,7 +187,8 @@ def register_endpoint(self, endpoint_cls):
186187
187188
:param endpoint_cls: A endpoint class
188189
"""
189-
self._endpoints[endpoint_cls.ENDPOINT_NAME] = endpoint_cls(self)
190+
endpoints = self._endpoints.setdefault(endpoint_cls.ENDPOINT_NAME, [])
191+
endpoints.append(endpoint_cls(self))
190192

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

234-
endpoint = self._endpoints[name]
235-
request = endpoint.create_endpoint_request(request)
236-
try:
237-
return self.handle_response(*endpoint(request))
238-
except OAuth2Error as error:
239-
return self.handle_error_response(request, error)
236+
endpoints = self._endpoints[name]
237+
for endpoint in endpoints:
238+
request = endpoint.create_endpoint_request(request)
239+
try:
240+
return self.handle_response(*endpoint(request))
241+
except ContinueIteration:
242+
continue
243+
except OAuth2Error as error:
244+
return self.handle_error_response(request, error)
240245

241246
def create_authorization_response(self, request=None, grant_user=None):
242247
"""Validate authorization request and create authorization response.

0 commit comments

Comments
 (0)