Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 1ac0480

Browse files
committed
Add hmac signature to client
1 parent 549777d commit 1ac0480

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

interface.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@
4242
else:
4343
body = None
4444

45+
46+
# HMAC Signature Section
47+
with st.expander("HMAC Signature"):
48+
use_hmac = st.checkbox("Enable HMAC Signature", value=False)
49+
if use_hmac:
50+
secret_key = st.text_input("Secret Key", type="password")
51+
if secret_key:
52+
# Generate HMAC signature
53+
message_to_sign = body if body else url # Use body or URL as the message
54+
signature = client.hmac_generator(secret_key, message_to_sign)
55+
st.info(f"Generated Signature: `{signature}`")
56+
# Add signature to headers
57+
headers["X-Signature"] = signature
58+
else:
59+
st.warning("Please enter a secret key to generate the HMAC signature.")
60+
4561
# Send request button
4662
if st.button("Send Request"):
4763
# Manage requests

interface_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import socket
22
import ssl
3-
3+
import hmac
4+
import hashlib
45
class HTTPClient:
5-
6+
def hmac_generator(self, key, msg):
7+
return hmac.new(key.encode(), msg.encode(), hashlib.sha256).hexdigest()
8+
69
def parse_url(self, url):
710
"""Parses the URL and returns (host, port, path, use_ssl)."""
811
use_ssl = False

0 commit comments

Comments
 (0)