@@ -23,8 +23,8 @@ def __init__(self, signature_key: str, skip_url_validation: bool = False):
23
23
Note that when true, no query parameters should be trusted.
24
24
"""
25
25
super ().__init__ ()
26
- self .__signature_key = signature_key
27
- self .__skip_url_validation = skip_url_validation
26
+ self ._signature_key = signature_key
27
+ self ._skip_url_validation = skip_url_validation
28
28
29
29
def __str__ (self ) -> str :
30
30
return super ().__str__ ()
@@ -52,13 +52,13 @@ def validate_signature(self, signature: str, url: str, request_body: Union[bytes
52
52
"""
53
53
if not signature :
54
54
raise ValidationError ("Signature is empty" )
55
- if not self .__skip_url_validation and not url :
55
+ if not self ._skip_url_validation and not url :
56
56
raise ValidationError ("URL is empty" )
57
57
58
58
try :
59
59
claims = jwt .decode (
60
60
jwt = signature ,
61
- key = self .__signature_key ,
61
+ key = self ._signature_key ,
62
62
algorithms = RequestValidator .ALLOWED_ALGOS ,
63
63
options = {
64
64
"require" : ["iss" , "nbf" , "exp" ],
@@ -70,18 +70,17 @@ def validate_signature(self, signature: str, url: str, request_body: Union[bytes
70
70
except jwt .InvalidTokenError as err :
71
71
raise ValidationError (str (err )) from err
72
72
73
- if not self .__skip_url_validation :
73
+ if not self ._skip_url_validation :
74
74
expected_url_hash = hashlib .sha256 (url .encode ("utf-8" )).hexdigest ()
75
75
if not hmac .compare_digest (expected_url_hash , claims ["url_hash" ]):
76
76
raise ValidationError ("invalid jwt: claim url_hash is invalid" )
77
77
78
78
payload_hash = claims .get ("payload_hash" )
79
79
if not request_body and payload_hash :
80
80
raise ValidationError ("invalid jwt: claim payload_hash is set but actual payload is missing" )
81
- elif request_body and not payload_hash :
81
+ if request_body and not payload_hash :
82
82
raise ValidationError ("invalid jwt: claim payload_hash is not set but payload is present" )
83
- elif request_body and not hmac .compare_digest (hashlib .sha256 (request_body ).hexdigest (),
84
- payload_hash ):
83
+ if request_body and not hmac .compare_digest (hashlib .sha256 (request_body ).hexdigest (), payload_hash ):
85
84
raise ValidationError ("invalid jwt: claim payload_hash is invalid" )
86
85
87
86
return claims
0 commit comments