Skip to content

Commit 0ae4c39

Browse files
committed
More debug messages
1 parent 8d6470e commit 0ae4c39

File tree

8 files changed

+48
-13
lines changed

8 files changed

+48
-13
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"keys": [{"kty": "oct", "use": "enc", "kid": "enc", "k": "LrU7gu0Jcj_3XJ0cPeUuxA0-jq5H792-"}, {"kty": "oct", "use": "sig", "kid": "sig", "k": "FQguegtRW6c0fXxDhke8dIg9QDddiAYX"}]}
1+
{"keys": [{"kty": "oct", "use": "enc", "kid": "enc", "k": "GCizp3ewVRV0VZEef3VQwFve7n2QwAFI"}, {"kty": "oct", "use": "sig", "kid": "sig", "k": "QC2JxpVJXPDMpYv_h76jIrt_lA1P4KSu"}]}

example/flask_rp/templates/opbyuid.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h3>By entering your unique identifier:</h3>
1919
<input type="text" id="uid" name="uid" class="form-control" placeholder="UID" autofocus>
2020
<h3>an issuer ID</h3>
2121
<input type="text" id="dyn_iss" name="dyn_iss" class="form-control">
22-
<h3><em>Or</em> you can chose one of the preconfigured OpenID Connect Providers</h3>
22+
<h3><em>Or</em> you can choose one of the preconfigured OpenID Connect Providers</h3>
2323
<select name="static_iss">
2424
<option value=""></option>
2525
{% for op in providers %}

src/idpyoidc/client/client_auth.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,15 @@ def find_token_info(request: Union[Message, dict], token_type: str, service, **k
298298
request.c_param[token_type] = SINGLE_OPTIONAL_STRING
299299
return {token_type: _token, "token_type": "Bearer"}
300300

301+
_state = kwargs.get("state", kwargs.get("key"))
302+
_token_info = service.upstream_get("context").cstate.get_set(_state, claim=[token_type,
303+
"token_type"])
304+
301305
_token = kwargs.get("access_token", None)
302306
if _token:
303-
return {token_type: _token, "token_type": "Bearer"}
307+
return {token_type: _token, "token_type": _token_info["token_type"]}
304308
else:
305-
# Get the latest acquired token.
306-
_state = kwargs.get("state", kwargs.get("key"))
307-
return service.upstream_get("context").cstate.get_set(_state, claim=[token_type,
308-
"token_type"])
309+
return _token_info
309310

310311

311312
class BearerHeader(ClientAuthnMethod):
@@ -336,7 +337,7 @@ def construct(self, request=None, service=None, http_args=None, **kwargs):
336337
raise KeyError("No bearer token available")
337338

338339
# The authorization value starts with the token_type
339-
#if _token_info["token_type"].to_lower() != "bearer":
340+
# if _token_info["token_type"].to_lower() != "bearer":
340341
_bearer = f"{_token_info['token_type']} {_token_info[_token_type]}"
341342

342343
# Add 'Authorization' to the headers

src/idpyoidc/client/current.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,6 @@ def create_state(self, **kwargs):
105105
_key = self.create_key()
106106
self._db[_key] = kwargs
107107
return _key
108+
109+
def keys(self):
110+
return self._db.keys()

src/idpyoidc/client/oauth2/add_on/par.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from idpyoidc.client.client_auth import CLIENT_AUTHN_METHOD
77
from idpyoidc.message import Message
88
from idpyoidc.message.oauth2 import JWTSecuredAuthorizationRequest
9+
from idpyoidc.server.util import execute
910
from idpyoidc.util import instantiate
1011
from requests import request
1112

@@ -21,24 +22,41 @@ def push_authorization(request_args, service, **kwargs):
2122

2223
_context = service.upstream_get("context")
2324
method_args = _context.add_on["pushed_authorization"]
25+
logger.debug(f"PAR method args: {method_args}")
26+
logger.debug(f"PAR kwargs: {kwargs}")
27+
2428
if method_args["apply"] is False:
2529
return request_args
2630

2731
_http_method = method_args["http_client"]
32+
_httpc_params = service.upstream_get("unit").httpc_params
2833

2934
# Add client authentication if needed
3035
_headers = {}
3136
authn_method = method_args["authn_method"]
3237
if authn_method:
33-
if authn_method not in _context.client_authn_methods:
34-
_context.client_authn_methods[authn_method] = CLIENT_AUTHN_METHOD[authn_method]()
38+
if isinstance(authn_method, str):
39+
if authn_method not in _context.client_authn_methods:
40+
_context.client_authn_methods[authn_method] = CLIENT_AUTHN_METHOD[authn_method]()
41+
else:
42+
_name = ""
43+
for _name, spec in authn_method.items():
44+
if _name not in _context.client_authn_methods:
45+
_context.client_authn_methods[_name] = execute(spec)
46+
authn_method = _name
3547

3648
_args = {}
3749
if _context.issuer:
3850
_args["iss"] = _context.issuer
51+
if _name == "client_attestation":
52+
_wia = kwargs.get("client_attestation")
53+
if _wia:
54+
_args["client_attestation"] = _wia
55+
3956
_headers = service.get_headers(
4057
request_args, http_method=_http_method, authn_method=authn_method, **_args
4158
)
59+
_headers["Content-Type"] = "application/x-www-form-urlencoded"
4260

4361
# construct the message body
4462
if method_args["body_format"] == "urlencoded":
@@ -56,12 +74,13 @@ def push_authorization(request_args, service, **kwargs):
5674

5775
_body = _msg.to_urlencoded()
5876

59-
# Send it to the Pushed Authorization Request Endpoint
77+
# Send it to the Pushed Authorization Request Endpoint using POST
6078
resp = _http_method(
61-
method="GET",
79+
method="POST",
6280
url=_context.provider_info["pushed_authorization_request_endpoint"],
6381
data=_body,
6482
headers=_headers,
83+
**_httpc_params
6584
)
6685

6786
if resp.status_code == 200:

src/idpyoidc/client/oauth2/stand_alone_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ def finalize_auth(self, response: dict, behaviour_args: Optional[dict] = None):
436436
# got it from the wrong bloke
437437
raise ValueError("Impersonator {}".format(issuer))
438438

439+
_context.cstate.update(authorization_response["state"], authorization_response)
439440
_srv.update_service_context(authorization_response, key=authorization_response["state"])
440441
return authorization_response
441442

src/idpyoidc/server/client_authn.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ def _verify(
225225
get_client_id_from_token: Optional[Callable] = None,
226226
**kwargs,
227227
):
228+
logger.debug(f"Client Auth method: {self.tag}")
228229
token = authorization_token.split(" ", 1)[1]
229230
_context = self.upstream_get("context")
230231
client_id = ""
@@ -235,7 +236,10 @@ def _verify(
235236
raise BearerTokenAuthenticationError("Expired token")
236237
except KeyError:
237238
raise BearerTokenAuthenticationError("Unknown token")
238-
return {"token": token, "client_id": client_id}
239+
except Exception as err:
240+
logger.debug(f"Exception in {self.tag}")
241+
242+
return {"token": token, "client_id": client_id, "method": self.tag}
239243

240244

241245
class BearerBody(ClientSecretPost):
@@ -502,6 +506,8 @@ def verify_client(
502506
logger.info("Verifying auth using {} failed: {}".format(_method.tag, err))
503507
continue
504508

509+
logger.debug(f"Verify returned: {auth_info}")
510+
505511
if auth_info.get("method") == "none" and auth_info.get("client_id") is None:
506512
break
507513

@@ -542,6 +548,8 @@ def verify_client(
542548
continue
543549
break
544550

551+
logger.debug(f"Authn methods applied")
552+
545553
# store what authn method was used
546554
if "method" in auth_info and client_id:
547555
_request_type = request.__class__.__name__

src/idpyoidc/server/endpoint.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def parse_request(
228228

229229
# Verify that the client is allowed to do this
230230
auth_info = self.client_authentication(req, http_info, endpoint=self, **kwargs)
231+
LOGGER.debug(f"parse_request:auth_info:{auth_info}")
231232

232233
_client_id = auth_info.get("client_id", "")
233234
if _client_id:
@@ -239,6 +240,8 @@ def parse_request(
239240
else:
240241
_client_id = req.get("client_id")
241242

243+
LOGGER.debug(f"parse_request:auth_info:{auth_info}")
244+
242245
# verify that the request message is correct, may have to do it twice
243246
err_response = self.verify_request(
244247
request=req, keyjar=_keyjar, client_id=_client_id, verify_args=verify_args

0 commit comments

Comments
 (0)