|
11 | 11 | from idpyoidc.client.defaults import DEFAULT_RESPONSE_MODE |
12 | 12 | from idpyoidc.client.exception import ConfigurationError |
13 | 13 | from idpyoidc.client.exception import OidcServiceError |
| 14 | +from idpyoidc.client.exception import Unsupported |
14 | 15 | from idpyoidc.client.oauth2 import Client |
15 | 16 | from idpyoidc.client.oauth2 import dynamic_provider_info_discovery |
16 | 17 | from idpyoidc.client.oauth2.utils import pick_redirect_uri |
17 | 18 | from idpyoidc.exception import MessageException |
18 | 19 | from idpyoidc.exception import MissingRequiredAttribute |
19 | 20 | from idpyoidc.exception import NotForMe |
20 | 21 | from idpyoidc.message import Message |
21 | | -from idpyoidc.message.oauth2 import ResponseMessage |
22 | 22 | from idpyoidc.message.oauth2 import is_error_message |
| 23 | +from idpyoidc.message.oauth2 import ResponseMessage |
23 | 24 | from idpyoidc.message.oidc import AuthorizationRequest |
24 | 25 | from idpyoidc.message.oidc import AuthorizationResponse |
25 | 26 | from idpyoidc.message.oidc import Claims |
@@ -193,12 +194,19 @@ def init_authorization( |
193 | 194 | _context = self.get_context() |
194 | 195 | _response_type = self._get_response_type(_context, req_args) |
195 | 196 | _response_mode = self._get_response_mode(_context, _response_type, req_args) |
196 | | - |
197 | | - request_args = { |
198 | | - "redirect_uri": pick_redirect_uri( |
| 197 | + try: |
| 198 | + _redirect_uri = pick_redirect_uri( |
199 | 199 | _context, request_args=req_args, response_type=_response_type, |
200 | 200 | response_mode=_response_mode |
201 | | - ), |
| 201 | + ) |
| 202 | + except KeyError: |
| 203 | + raise Unsupported( |
| 204 | + 'Could not pick a redirect_uri based on the given response_type and response_mode') |
| 205 | + except [MissingRequiredAttribute, ValueError]: |
| 206 | + raise |
| 207 | + |
| 208 | + request_args = { |
| 209 | + "redirect_uri": _redirect_uri, |
202 | 210 | "response_type": _response_type, |
203 | 211 | } |
204 | 212 |
|
@@ -247,21 +255,22 @@ def init_authorization( |
247 | 255 | @staticmethod |
248 | 256 | def get_client_authn_method(self, endpoint): |
249 | 257 | """ |
250 | | - Return the client authentication method a client wants to use a |
| 258 | + Return the client authentication method a client wants to use at a |
251 | 259 | specific endpoint |
252 | 260 |
|
253 | 261 | :param endpoint: The endpoint at which the client has to authenticate |
254 | 262 | :return: The client authentication method |
255 | 263 | """ |
256 | 264 | if endpoint == "token_endpoint": |
257 | | - am = self.get_context().get_usage("token_endpoint_auth_method") |
258 | | - if not am: |
| 265 | + auth_method = self.get_context().get_usage("token_endpoint_auth_method") |
| 266 | + if not auth_method: |
259 | 267 | return "" |
260 | 268 | else: |
261 | | - if isinstance(am, str): |
262 | | - return am |
| 269 | + if isinstance(auth_method, str): |
| 270 | + return auth_method |
263 | 271 | else: # a list |
264 | | - return am[0] |
| 272 | + return auth_method[0] |
| 273 | + return "" |
265 | 274 |
|
266 | 275 | def get_tokens(self, state): |
267 | 276 | """ |
@@ -431,7 +440,7 @@ def finalize_auth( |
431 | 440 |
|
432 | 441 | def get_access_and_id_token( |
433 | 442 | self, |
434 | | - authorization_response=None, |
| 443 | + authorization_response: Optional[Message] = None, |
435 | 444 | state: Optional[str] = "", |
436 | 445 | behaviour_args: Optional[dict] = None, |
437 | 446 | ): |
@@ -663,10 +672,10 @@ def logout( |
663 | 672 | else: |
664 | 673 | request_args = {} |
665 | 674 |
|
666 | | - resp = srv.get_request_parameters(state=state, request_args=request_args) |
| 675 | + _info = srv.get_request_parameters(state=state, request_args=request_args) |
667 | 676 |
|
668 | | - logger.debug(f"EndSession Request: {resp}") |
669 | | - return resp |
| 677 | + logger.debug(f"EndSession Request: {_info['request'].to_dict()}") |
| 678 | + return _info |
670 | 679 |
|
671 | 680 | def close( |
672 | 681 | self, state: str, post_logout_redirect_uri: Optional[str] = "" |
|
0 commit comments