Skip to content

Commit dde5433

Browse files
committed
A default key_conf will only be applied if the Server is not part of a combo.
Added more resilience. Wrong method was used for the pushed auth test.
1 parent c80f986 commit dde5433

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

src/idpyoidc/client/client_auth.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
__author__ = "roland hedberg"
3131

32+
DEFAULT_ACCESS_TOKEN_TYPE = "Bearer"
3233

3334
class AuthnFailure(Exception):
3435
"""Unspecified Authentication failure"""
@@ -296,11 +297,14 @@ def find_token_info(request: Union[Message, dict], token_type: str, service, **k
296297
del request[token_type]
297298
# Required under certain circumstances :-) not under other
298299
request.c_param[token_type] = SINGLE_OPTIONAL_STRING
299-
return {token_type: _token, "token_type": "Bearer"}
300+
return {token_type: _token, "token_type": DEFAULT_ACCESS_TOKEN_TYPE}
300301

301302
_state = kwargs.get("state", kwargs.get("key"))
302-
_token_info = service.upstream_get("context").cstate.get_set(_state, claim=[token_type,
303-
"token_type"])
303+
if _state:
304+
_token_info = service.upstream_get("context").cstate.get_set(
305+
_state, claim=[token_type, "token_type"])
306+
else:
307+
_token_info = {"token_type": DEFAULT_ACCESS_TOKEN_TYPE}
304308

305309
_token = kwargs.get("access_token", None)
306310
if _token:

src/idpyoidc/server/__init__.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77

88
from cryptojwt import KeyJar
99

10+
from idpyoidc.client.defaults import DEFAULT_KEY_DEFS
1011
from idpyoidc.node import Unit
11-
1212
# from idpyoidc.server import authz
1313
# from idpyoidc.server.client_authn import client_auth_setup
1414
from idpyoidc.server.configure import ASConfiguration
1515
from idpyoidc.server.configure import OPConfiguration
1616
from idpyoidc.server.endpoint import Endpoint
1717
from idpyoidc.server.endpoint_context import EndpointContext
18-
1918
# from idpyoidc.server.session.manager import create_session_manager
2019
# from idpyoidc.server.user_authn.authn_context import populate_authn_broker
2120
from idpyoidc.server.util import allow_refresh_token
@@ -36,20 +35,26 @@ class Server(Unit):
3635
parameter = {"endpoint": [Endpoint], "context": EndpointContext}
3736

3837
def __init__(
39-
self,
40-
conf: Union[dict, OPConfiguration, ASConfiguration],
41-
keyjar: Optional[KeyJar] = None,
42-
cwd: Optional[str] = "",
43-
cookie_handler: Optional[Any] = None,
44-
httpc: Optional[Callable] = None,
45-
upstream_get: Optional[Callable] = None,
46-
httpc_params: Optional[dict] = None,
47-
entity_id: Optional[str] = "",
48-
key_conf: Optional[dict] = None,
38+
self,
39+
conf: Union[dict, OPConfiguration, ASConfiguration],
40+
keyjar: Optional[KeyJar] = None,
41+
cwd: Optional[str] = "",
42+
cookie_handler: Optional[Any] = None,
43+
httpc: Optional[Callable] = None,
44+
upstream_get: Optional[Callable] = None,
45+
httpc_params: Optional[dict] = None,
46+
entity_id: Optional[str] = "",
47+
key_conf: Optional[dict] = None,
4948
):
5049
self.entity_id = entity_id or conf.get("entity_id")
5150
self.issuer = conf.get("issuer", self.entity_id)
5251

52+
if upstream_get is None:
53+
if key_conf is None:
54+
_conf = conf.get("key_conf")
55+
if _conf is None:
56+
key_conf = {"key_defs": DEFAULT_KEY_DEFS}
57+
5358
Unit.__init__(
5459
self,
5560
config=conf,

tests/test_client_29_pushed_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_authorization(self):
5757
with responses.RequestsMock() as rsps:
5858
_resp = {"request_uri": "urn:example:bwc4JK-ESC0w8acc191e-Y1LTC2", "expires_in": 3600}
5959
rsps.add(
60-
"GET",
60+
"POST",
6161
auth_service.upstream_get("context").provider_info[
6262
"pushed_authorization_request_endpoint"
6363
],

tests/test_client_30_rph_defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_init_client(self):
5252
_keyjar = client.get_attribute("keyjar")
5353
assert list(_keyjar.owners()) == ["", BASE_URL]
5454
keys = _keyjar.get_issuer_keys("")
55-
assert len(keys) == 4
55+
assert len(keys) == 2
5656

5757
assert _context.base_url == BASE_URL
5858

0 commit comments

Comments
 (0)