Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 711c799

Browse files
committed
Sformat needed to be carried.
1 parent 71ff1e2 commit 711c799

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

src/oidcmsg/message.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ def from_dict(self, dictionary, **kwargs):
314314
self._dict[key] = val
315315
continue
316316

317-
self._add_value(skey, vtyp, key, val, _deser, null_allowed)
317+
self._add_value(skey, vtyp, key, val, _deser, null_allowed, sformat="dict")
318318
return self
319319

320-
def _add_value(self, skey, vtyp, key, val, _deser, null_allowed):
320+
def _add_value(self, skey, vtyp, key, val, _deser, null_allowed, sformat="urlencoded"):
321321
"""
322322
Main method for adding a value to the instance. Does all the
323323
checking on type of value and if among allowed values.
@@ -350,7 +350,7 @@ def _add_value(self, skey, vtyp, key, val, _deser, null_allowed):
350350
self._dict[skey] = [val]
351351
elif _deser:
352352
try:
353-
self._dict[skey] = _deser(val, sformat="urlencoded")
353+
self._dict[skey] = _deser(val, sformat=sformat)
354354
except Exception as exc:
355355
raise DecodeError(ERRTXT % (key, exc))
356356
else:
@@ -402,16 +402,6 @@ def _add_value(self, skey, vtyp, key, val, _deser, null_allowed):
402402
except Exception as exc:
403403
raise DecodeError(ERRTXT % (key, exc))
404404
else:
405-
# if isinstance(val, str):
406-
# self._dict[skey] = val
407-
# elif isinstance(val, list):
408-
# if len(val) == 1:
409-
# self._dict[skey] = val[0]
410-
# elif not len(val):
411-
# pass
412-
# else:
413-
# raise TooManyValues(key)
414-
# else:
415405
self._dict[skey] = val
416406
elif vtyp is int:
417407
try:
@@ -863,8 +853,12 @@ def add_non_standard(msg1, msg2):
863853

864854

865855
def list_serializer(vals, sformat="urlencoded", lev=0):
866-
if isinstance(vals, str) or not isinstance(vals, list):
856+
if isinstance(vals, str) and sformat == "dict":
857+
return [vals]
858+
859+
if not isinstance(vals, list):
867860
raise ValueError("Expected list: %s" % vals)
861+
868862
if sformat == "urlencoded":
869863
return " ".join(vals)
870864
else:

src/oidcmsg/oidc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ def verify(self, **kwargs):
797797
# check that I'm among the recipients
798798
if kwargs["client_id"] not in self["aud"]:
799799
raise NotForMe(
800-
"{} not in aud:{}".format(kwargs["client_id"], self["aud"]), self
800+
'"{}" not in {}'.format(kwargs["client_id"], self["aud"]), self
801801
)
802802

803803
# Then azp has to be present and be one of the aud values

tests/test_06_oidc.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@
66
from urllib.parse import parse_qs
77
from urllib.parse import urlencode
88

9-
import pytest
109
from cryptojwt.exception import BadSignature
1110
from cryptojwt.exception import UnsupportedAlgorithm
1211
from cryptojwt.jws.exception import SignerAlgError
1312
from cryptojwt.jws.utils import left_hash
1413
from cryptojwt.jwt import JWT
1514
from cryptojwt.key_bundle import KeyBundle
1615
from cryptojwt.key_jar import KeyJar
16+
import pytest
1717

1818
from oidcmsg import proper_path
1919
from oidcmsg import time_util
2020
from oidcmsg.exception import MessageException
2121
from oidcmsg.exception import MissingRequiredAttribute
2222
from oidcmsg.exception import NotAllowedValue
2323
from oidcmsg.exception import OidcMsgError
24-
from oidcmsg.oauth2 import ResponseMessage
2524
from oidcmsg.oauth2 import ROPCAccessTokenRequest
26-
from oidcmsg.oidc import JRD
25+
from oidcmsg.oauth2 import ResponseMessage
2726
from oidcmsg.oidc import AccessTokenRequest
2827
from oidcmsg.oidc import AccessTokenResponse
2928
from oidcmsg.oidc import AddressClaim
@@ -38,6 +37,7 @@
3837
from oidcmsg.oidc import EXPError
3938
from oidcmsg.oidc import IATError
4039
from oidcmsg.oidc import IdToken
40+
from oidcmsg.oidc import JRD
4141
from oidcmsg.oidc import Link
4242
from oidcmsg.oidc import OpenIDSchema
4343
from oidcmsg.oidc import ProviderConfigurationResponse
@@ -661,7 +661,7 @@ def test_deserialize(self):
661661
"client_secret_expires_at": 1577858400,
662662
"registration_access_token": "this.is.an.access.token.value.ffx83",
663663
"registration_client_uri": "https://server.example.com/connect/register?client_id"
664-
"=s6BhdRkqt3",
664+
"=s6BhdRkqt3",
665665
"token_endpoint_auth_method": "client_secret_basic",
666666
"application_type": "web",
667667
"redirect_uris": [
@@ -1601,3 +1601,17 @@ def test_correct_sign_alg():
16011601
client_id="554295ce3770612820620000",
16021602
allowed_sign_alg="HS256",
16031603
)
1604+
1605+
1606+
def test_ID_Token_space_in_id():
1607+
idt = IdToken(**{
1608+
"at_hash": "buCCujNN632UIV8-VbKhgw",
1609+
"sub": "user-subject-1234531",
1610+
"aud": "client_ifCttPphtLxtPWd20602 ^.+/",
1611+
"iss": "https://www.certification.openid.net/test/a/idpy/",
1612+
"exp": 1632495959,
1613+
"nonce": "B88En9UpdHkQZMQXK9U3KHzV",
1614+
"iat": 1632495659
1615+
})
1616+
1617+
assert idt["aud"] == "client_ifCttPphtLxtPWd20602 ^.+/"

0 commit comments

Comments
 (0)