Skip to content

Commit d2487f6

Browse files
committed
Being more explicit on what type of client it is.
Deal with policy expressed in two claims: metadata and metadata_policy.
1 parent 04ff81e commit d2487f6

File tree

12 files changed

+52
-17
lines changed

12 files changed

+52
-17
lines changed

src/idpyoidc/client/claims/transform.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,31 @@ def array_or_singleton(claim_spec, values):
112112

113113

114114
def _is_subset(a, b):
115+
# Is 'a' a subset of 'b'
115116
if isinstance(a, list):
116117
if isinstance(b, list):
117-
return set(b).issubset(set(a))
118+
return set(a).issubset(set(b))
118119
elif isinstance(b, list):
119120
return a in b
120121
else:
121122
return a == b
122123

124+
def _intersection(a, b):
125+
res = None
126+
if isinstance(a, list):
127+
if isinstance(b, list):
128+
res = list(set(a).intersection(set(b)))
129+
else:
130+
if b in a:
131+
res = b
132+
else:
133+
res = []
134+
elif isinstance(b, list):
135+
if a in b:
136+
res = [a]
137+
else:
138+
res = []
139+
return res
123140

124141
def preferred_to_registered(prefers: dict, supported: dict,
125142
registration_response: Optional[dict] = None):
@@ -136,10 +153,19 @@ def preferred_to_registered(prefers: dict, supported: dict,
136153
if registration_response:
137154
for key, val in registration_response.items():
138155
if key in REGISTER2PREFERRED:
139-
if _is_subset(val, supported.get(REGISTER2PREFERRED[key])):
156+
# Is the response value with in what this instance supports
157+
_supports = supported.get(REGISTER2PREFERRED[key])
158+
if _is_subset(val, _supports):
140159
registered[key] = val
141160
else:
142-
logger.warning(f'OP tells me to do something I do not support: {key} = {val}')
161+
logger.warning(
162+
f'OP tells me to do something I do not support: (key) = {val} not within '
163+
f'{_supports}')
164+
_val = _intersection(val, _supports)
165+
if _val:
166+
registered[key] = _val
167+
else:
168+
raise ValueError('Not able to support the OPs choice')
143169
else:
144170
registered[key] = val # Should I just accept with the OP says ??
145171

src/idpyoidc/client/entity.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from idpyoidc.client.client_auth import method_to_item
1414
from idpyoidc.client.configure import Configuration
1515
from idpyoidc.client.defaults import DEFAULT_OAUTH2_SERVICES
16+
from idpyoidc.client.defaults import DEFAULT_OIDC_SERVICES
1617
from idpyoidc.client.service import init_services
1718
from idpyoidc.client.service_context import ServiceContext
1819
from idpyoidc.context import OidcContext
@@ -75,7 +76,7 @@ def redirect_uris_from_callback_uris(callback_uris):
7576
return res
7677

7778

78-
class Entity(Unit): # This is a Client
79+
class Entity(Unit): # This is a Client. What type is undefined here.
7980
parameter = {
8081
'entity_id': None,
8182
'jwks_uri': None,
@@ -117,7 +118,10 @@ def __init__(
117118
_srvs = None
118119

119120
if not _srvs:
120-
_srvs = DEFAULT_OAUTH2_SERVICES
121+
if client_type == 'oauth2':
122+
_srvs = DEFAULT_OAUTH2_SERVICES
123+
else:
124+
_srvs = DEFAULT_OIDC_SERVICES
121125

122126
self._service = init_services(service_definitions=_srvs, upstream_get=self.unit_get)
123127

src/idpyoidc/client/oauth2/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ExpiredToken(Exception):
3737

3838

3939
class Client(Entity):
40+
client_type = 'oauth2'
4041
def __init__(
4142
self,
4243
keyjar: Optional[KeyJar] = None,
@@ -69,7 +70,7 @@ def __init__(
6970
"""
7071

7172
if not client_type:
72-
client_type = "oauth2"
73+
client_type = self.client_type
7374

7475
if verify_ssl is False:
7576
# just ignore verify_ssl until it goes away

src/idpyoidc/client/oauth2/server_metadata.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def _update_service_context(self, resp):
118118
# that. Otherwise, a new Key Jar is minted
119119
try:
120120
_keyjar = self.upstream_get('attribute', 'keyjar')
121+
if _keyjar is None:
122+
_keyjar = KeyJar()
121123
except KeyError:
122124
_keyjar = KeyJar()
123125

src/idpyoidc/client/oidc/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class FetchException(Exception):
7777

7878

7979
class RP(oauth2.Client):
80+
client_type = 'oidc'
8081

8182
def __init__(
8283
self,
@@ -93,7 +94,10 @@ def __init__(
9394
**kwargs
9495
):
9596
self.upstream_get = upstream_get
96-
_srvs = services or DEFAULT_OIDC_SERVICES
97+
if services:
98+
_srvs = services
99+
else:
100+
_srvs = config.get("services", DEFAULT_OIDC_SERVICES)
97101

98102
oauth2.Client.__init__(
99103
self,

src/idpyoidc/client/oidc/access_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class AccessToken(access_token.AccessToken):
2424
default_authn_method = "client_secret_basic"
2525

2626
_supports = {
27-
"token_endpoint_auth_method": get_client_authn_methods,
27+
"token_endpoint_auth_methods_supported": get_client_authn_methods,
2828
"token_endpoint_auth_signing_alg_values_supported": get_signing_algs
2929
}
3030

src/idpyoidc/client/provider/github.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AccessToken(access_token.AccessToken):
2828
response_body_type = "urlencoded"
2929

3030
_supports = {
31-
"token_endpoint_auth_method": get_client_authn_methods,
31+
"token_endpoint_auth_methods_supported": get_client_authn_methods,
3232
"token_endpoint_auth_signing_alg_values_supported": get_signing_algs
3333
}
3434

src/idpyoidc/client/provider/linkedin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class AccessToken(access_token.AccessToken):
3434
error_msg = oauth2.TokenErrorResponse
3535

3636
_supports = {
37-
"token_endpoint_auth_method": get_client_authn_methods,
37+
"token_endpoint_auth_methods_supported": get_client_authn_methods,
3838
"token_endpoint_auth_signing_alg_values_supported": get_signing_algs
3939
}
4040

src/idpyoidc/client/service.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,9 @@ def construct_uris(self,
674674
else:
675675
_path = self._callback_path.get(uri)
676676
if isinstance(_path, str):
677-
_callback_uris[uri] = self.get_uri(base_url, self._callback_path.get(_path),
678-
hex)
677+
_callback_uris[uri] = self.get_uri(base_url, _path, hex)
679678
else:
680-
_callback_uris[uri] = [self.get_uri(base_url, self._callback_path.get(_var),
681-
hex) for _var in _path]
679+
_callback_uris[uri] = [self.get_uri(base_url, _var, hex) for _var in _path]
682680

683681
return _callback_uris
684682

src/idpyoidc/server/client_authn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def verify_client(
451451
get_client_id_from_token: Optional[Callable] = None,
452452
endpoint=None, # Optional[Endpoint]
453453
also_known_as: Optional[Dict[str, str]] = None,
454-
):
454+
) -> dict:
455455
"""
456456
Initiated Guessing !
457457

0 commit comments

Comments
 (0)