1212
1313from cryptojwt import as_unicode
1414from cryptojwt .jws .utils import left_hash
15+ from cryptojwt .jwt import JWT
16+ from cryptojwt .key_jar import KeyJar
1517
1618from oidcmsg import oauth2
1719from oidcmsg import time_util
@@ -183,14 +185,15 @@ def claims_request_deser(val, sformat="json"):
183185
184186
185187def dict_deser (val , sformat = "json" ):
186- # never 'urlencoded'
188+ # never 'urlencoded', silently correct
187189 if sformat == "urlencoded" :
188190 sformat = "json"
191+
189192 if sformat in ["dict" , "json" ]:
190193 if not isinstance (val , str ):
191194 val = json .dumps (val )
192- elif isinstance ( val , dict ):
193- return val
195+
196+ return val
194197 else :
195198 raise ValueError ('sformat can not be "{}"' .format (sformat ))
196199
@@ -426,11 +429,20 @@ def verify(self, **kwargs):
426429 # Try to decode the JWT, checks the signature
427430 oidr = OpenIDRequest ().from_jwt (str (self ["request" ]), ** args )
428431
429- # verify that nothing is change in the original message
432+ # check if something is change in the original message
430433 for key , val in oidr .items ():
431434 if key in self :
432435 if self [key ] != val :
433- raise ValueError ('{} != {}' .format (self [key ], val ))
436+ # log but otherwise ignore
437+ logger .warning ('{} != {}' .format (self [key ], val ))
438+
439+ # remove all claims
440+ _keys = list (self .keys ())
441+ for key in _keys :
442+ if key not in oidr :
443+ del self [key ]
444+
445+ self .update (oidr )
434446
435447 # replace the JWT with the parsed and verified instance
436448 self [verified_claim_name ("request" )] = oidr
@@ -1178,48 +1190,25 @@ def factory(msgtype, **kwargs):
11781190 return oauth2 .factory (msgtype , ** kwargs )
11791191
11801192
1181- def make_openid_request (arq , keys = None , userinfo_claims = None ,
1182- idtoken_claims = None , request_object_signing_alg = None ,
1183- ** kwargs ):
1193+ def make_openid_request (arq , keys , issuer , request_object_signing_alg , recv ):
11841194 """
11851195 Construct the JWT to be passed by value (the request parameter) or by
11861196 reference (request_uri).
11871197 The request will be signed
11881198
11891199 :param arq: The Authorization request
11901200 :param keys: Keys to use for signing/encrypting
1191- :param userinfo_claims: UserInfo claims
1192- :param idtoken_claims: IdToken claims
1201+ :param issuer: Who is signing this JSON Web Token
11931202 :param request_object_signing_alg: Which signing algorithm to use
1203+ :param recv: The intended receiver of the request
11941204 :return: JWT encoded OpenID request
11951205 """
11961206
1197- oir_args = {}
1198- for prop in OpenIDRequest .c_param .keys ():
1199- try :
1200- oir_args [prop ] = arq [prop ]
1201- except KeyError :
1202- pass
1203-
1204- for attr in ["scope" , "response_type" ]:
1205- if attr in oir_args :
1206- oir_args [attr ] = " " .join (oir_args [attr ])
1207-
1208- c_args = {}
1209- if userinfo_claims is not None :
1210- # UserInfoClaims
1211- c_args ["userinfo" ] = Claims (** userinfo_claims )
1212-
1213- if idtoken_claims is not None :
1214- # IdTokenClaims
1215- c_args ["id_token" ] = Claims (** idtoken_claims )
1207+ if isinstance (keys , KeyJar ):
1208+ keys = keys .get_signing_key ()
12161209
1217- if c_args :
1218- oir_args ["claims" ] = ClaimsRequest (** c_args )
1219-
1220- oir = OpenIDRequest (** oir_args )
1221-
1222- return oir .to_jwt (key = keys , algorithm = request_object_signing_alg )
1210+ _jwt = JWT (own_keys = keys , iss = issuer , sign_alg = request_object_signing_alg )
1211+ return _jwt .pack (arq .to_dict (), owner = issuer , recv = recv )
12231212
12241213
12251214def claims_match (value , claimspec ):
@@ -1230,7 +1219,7 @@ def claims_match(value, claimspec):
12301219 Also the text doesn't prohibit claims specification having both 'value'
12311220 and 'values'.
12321221
1233- :param value: single value or list of values
1222+ :param value: single value
12341223 :param claimspec: None or a dictionary with 'essential', 'value' or 'values'
12351224 as keys
12361225 :return: Boolean
@@ -1253,8 +1242,8 @@ def claims_match(value, claimspec):
12531242 if matched :
12541243 break
12551244
1256- if matched is False :
1257- if list (claimspec .keys ()) == ['essential' ]:
1258- return True
1245+ # No values to test against so it's just about being there or not
1246+ if list (claimspec .keys ()) == ['essential' ]:
1247+ return True
12591248
12601249 return matched
0 commit comments