8000 Added a better way to generate oAuth nonces #11 · seedwithroot/wc-api-python@00bc2fe · GitHub
[go: up one dir, main page]

Skip to content

Commit 00bc2fe

Browse files
Added a better way to generate oAuth nonces woocommerce#11
1 parent ef70002 commit 00bc2fe

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

woocommerce/oauth.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ def get_oauth_url(self):
5050

5151
params["oauth_consumer_key"] = self.consumer_key
5252
params["oauth_timestamp"] = int(time())
53-
params["oauth_nonce"] = HMAC(
54-
str(time() + randint(0, 99999)).encode(),
55-
"secret".encode(),
56-
sha1
57-
).hexdigest()
53+
params["oauth_nonce"] = self.generate_nonce()
5854
params["oauth_signature_method"] = "HMAC-SHA256"
5955
params["oauth_signature"] = self.generate_oauth_signature(params, url)
6056

@@ -131,3 +127,13 @@ def get_value_like_as_php(val):
131127
normalized_parameters[key] = value
132128

133129
return normalized_parameters
130+
131+
@staticmethod
132+
def generate_nonce():
133+
""" Generate nonce number """
134+
nonce = ''.join([str(randint(0, 9)) for i in range(8)])
135+
return HMAC(
136+
nonce.encode(),
137+
"secret".encode(),
138+
sha1
139+
).hexdigest()

0 commit comments

Comments
 (0)
0