73 lines
2.7 KiB
Python
73 lines
2.7 KiB
Python
import requests
|
|
import hashlib
|
|
import hmac
|
|
import json
|
|
import uuid
|
|
|
|
# nTransit Shared Secret Key
|
|
# secret_key = b'IU9BRsR7WTDWdDooX4w9DFLqweAZreLwaDDaLnVRkHZeubcSdA'
|
|
|
|
# Spark Shared Secret Key
|
|
secret_key = b'DK9BRsR7WTDWdDooX4w9DFLnqjAZreLwaFFaLnVRkHZeubcKdR'
|
|
|
|
prod_url = "https://walmart.northpass.io/helpMenu"
|
|
driver_auth = "https://walmart.northpass.io/driver/authenticate"
|
|
stage_url = "https://walmart.np-mt-dev.net/helpMenu"
|
|
random_uuid = uuid.uuid4()
|
|
|
|
# msg_body = {
|
|
# "sessionExpiryTimeInSeconds": 3600,
|
|
# "messageExpirationTimestamp": 1758722640,
|
|
# "driver": {
|
|
# "uuid": str(random_uuid),
|
|
# "accessLevel": "BEGINNER"
|
|
# },
|
|
# "subCategory": "REWARDS",
|
|
# "appContext": "contextAwareHelp"
|
|
# }
|
|
msg_body = {"sessionExpiryTimeInSeconds":3600,"messageExpirationTimestamp":1758722640,"driver":{"uuid":str(random_uuid),"accessLevel":"BEGINNER"},"subCategory":"REWARDS","appContext":"contextAwareHelp"}
|
|
print(msg_body)
|
|
|
|
msg_body_json = json.dumps(msg_body, sort_keys=True)
|
|
print(msg_body_json)
|
|
body_signature = hmac.new(secret_key, msg_body_json.encode('utf-8'), hashlib.sha256).hexdigest()
|
|
|
|
# "accept": "application/json",
|
|
# "X-Api-Key": "6hUfJdAartHTHhHc0WIRZYPWe",
|
|
header = {
|
|
"X-Hmac-SHA256": 'fec9bb0355b2b599d6cfc22c73b5e8df3159d0b8b275af5229c900e29e3081c8'
|
|
}
|
|
|
|
# canonical_headers = '\n'.join(f'{k.lower()}:{v.strip()}' for k, v in sorted(headers.items()))
|
|
# header_signature = hmac.new(secret_key, canonical_headers.encode('utf-8'), hashlib.sha256).hexdigest()
|
|
headers = { 'Content-Type': 'application/json','X-Hmac-SHA256': body_signature }
|
|
|
|
# prod = requests.post(prod_url, headers=headers, json=msg_body)
|
|
prod = requests.post(prod_url, headers=headers, json=msg_body_json)
|
|
print(f"Status Code: {prod.status_code}")
|
|
print(f"Response: {prod.json()}")
|
|
print(f"Body Signature: {body_signature}")
|
|
# print(f"Header Signature: {header_signature}")
|
|
|
|
"""
|
|
This is a valid curl request for nTransit:
|
|
|
|
curl -X POST --location "https://ntransit.northpass.io/driver/authenticate" \
|
|
-H "X-Hmac-SHA256: SECRET" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"sessionExpiryTimeInSeconds": 3600,
|
|
"messageExpirationTimestamp": 1758722640,
|
|
"driver": {
|
|
"uuid": "3949c78e-9a9c-43d6-92f0-8c474c0e1d1e",
|
|
"zone": "Zone 1"
|
|
}
|
|
}'
|
|
|
|
Testing the same curl respone for Spark:
|
|
curl -X POST --location "https://walmart.northpass.io/helpMenu" \
|
|
-H "X-Hmac-SHA256: fec9bb0355b2b599d6cfc22c73b5e8df3159d0b8b275af5229c900e29e3081c8" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"sessionExpiryTimeInSeconds":3600,"messageExpirationTimestamp":1758722640,"driver":{"uuid":"3949c78e-9a9c-43d6-92f0-8c474c0e1d1e","accessLevel":"BEGINNER"},"subCategory":"REWARDS","appContext":"contextAwareHelp"}'
|
|
"""
|