@@ -103,6 +103,34 @@ class AuthorizationRequest(Message):
103103 "state" : SINGLE_OPTIONAL_STRING ,
104104 }
105105
106+ def merge (self , request_object , treatement = "strict" , whitelist = None ):
107+ """
108+ How to combine parameter that appear in the request with parameters that
109+ appear in the request object.
110+
111+ :param request: The original request
112+ :param request_object: The result of parsing the request/request_uri parameter
113+ :param treatement: How to do the merge strict/lax/whitelist
114+ :param whitelist: If whitelisted parameters from the request should be included in the
115+ result, this is the list to use.
116+ """
117+
118+ if treatement == 'strict' :
119+ params = list (self .keys ())
120+ # remove all parameters in request that does not appear in request_object
121+ for param in params :
122+ if param not in request_object :
123+ del self [param ]
124+ elif treatement == "lax" :
125+ pass
126+ elif treatement == "whitelist" and whitelist :
127+ params = list (self .keys ())
128+ for param in params :
129+ if param not in whitelist :
130+ del self [param ]
131+
132+ self .update (request_object )
133+
106134
107135class AuthorizationResponse (ResponseMessage ):
108136 """
@@ -285,7 +313,7 @@ def verify(self, **kwargs):
285313 pass
286314
287315 _req = AuthorizationRequest ().from_jwt (str (self ["request" ]), ** args )
288- self .update (_req )
316+ self .merge (_req , 'strict' )
289317 self [_vc_name ] = _req
290318 elif "request_uri" not in self :
291319 raise MissingAttribute ("One of request or request_uri must be present" )
@@ -314,7 +342,7 @@ def verify(self, **kwargs):
314342 pass
315343
316344 _req = AuthorizationRequest ().from_jwt (str (self ["request" ]), ** args )
317- self .update (_req )
345+ self .merge (_req , "lax" )
318346 self [_vc_name ] = _req
319347
320348 return True
0 commit comments