@@ -114,7 +114,9 @@ def decode(self, jwt, key='', verify=True, algorithms=None, **kwargs):
114114
115115 if verify :
116116 self ._verify_signature (payload , signing_input , header , signature ,
117- key , algorithms , ** kwargs )
117+ key , algorithms )
118+
119+ self ._validate_claims (payload , ** kwargs )
118120
119121 return payload
120122
@@ -157,20 +159,13 @@ def _load(self, jwt):
157159 return (payload , signing_input , header , signature )
158160
159161 def _verify_signature (self , payload , signing_input , header , signature ,
160- key = '' , algorithms = None , verify_expiration = True , leeway = 0 ,
161- audience = None , issuer = None ):
162+ key = '' , algorithms = None ):
162163
163164 alg = header ['alg' ]
164165
165166 if algorithms is not None and alg not in algorithms :
166167 raise InvalidAlgorithmError ('The specified alg value is not allowed' )
167168
168- if isinstance (leeway , timedelta ):
169- leeway = timedelta_total_seconds (leeway )
170-
171- if not isinstance (audience , (string_types , type (None ))):
172- raise TypeError ('audience must be a string or None' )
173-
174169 try :
175170 alg_obj = self ._algorithms [alg ]
176171 key = alg_obj .prepare_key (key )
@@ -181,6 +176,14 @@ def _verify_signature(self, payload, signing_input, header, signature,
181176 except KeyError :
182177 raise InvalidAlgorithmError ('Algorithm not supported' )
183178
179+ def _validate_claims (self , payload , verify_expiration = True , leeway = 0 ,
180+ audience = None , issuer = None ):
181+ if isinstance (leeway , timedelta ):
182+ leeway = timedelta_total_seconds (leeway )
183+
184+ if not isinstance (audience , (string_types , type (None ))):
185+ raise TypeError ('audience must be a string or None' )
186+
184187 if 'iat' in payload :
185188 try :
186189 int (payload ['iat' ])
@@ -228,6 +231,7 @@ def _verify_signature(self, payload, signing_input, header, signature,
228231 if payload .get ('iss' ) != issuer :
229232 raise InvalidIssuerError ('Invalid issuer' )
230233
234+
231235_jwt_global_obj = PyJWT ()
232236encode = _jwt_global_obj .encode
233237decode = _jwt_global_obj .decode
0 commit comments