Skip to content

Commit

Permalink
Updated jwt tries
Browse files Browse the repository at this point in the history
  • Loading branch information
visch committed Dec 20, 2024
1 parent 0acbb04 commit bfcbfb0
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions scripts/generate_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import os
import uuid
import base64
import requests
from dotenv import load_dotenv

def generate_jwt_token():
def generate_token():
"""
Docs: https://emr.sunwavehealth.com/SunwaveEMR/swagger/
"""
Expand All @@ -23,23 +24,22 @@ def generate_jwt_token():
unique_transaction_id = str(uuid.uuid4())

seed = f"{user_id}:{client_id}:{dateTimeBase64}:{clinic_id}:{unique_transaction_id}"
hmac_token = hmac.new(
key=client_secret.encode(),
msg=seed.encode(),
digestmod=hashlib.sha256
).hexdigest()

jwt_token = jwt.encode(
payload={
"seed": seed
seed: client_secret
},
key=client_secret,
key=seed,
algorithm="HS256"
)

return (f"{seed}:{hmac_token}", f"{seed}:{jwt_token}")
return f"{jwt_token}"

if __name__ == "__main__":
hmac_token, jwt_token = generate_jwt_token()
with open(".secrets/token_out.txt", "w") as file:
file.write(f"HMAC TOKEN:\n{hmac_token}\n\nJWT TOKEN:\n{jwt_token}")

url_base = "https://emr.sunwavehealth.com/SunwaveEMR"
url_path = "/api/users"
response = requests.get(url_base + url_path, headers={"Authorization": f"Digest {generate_token()}"})
print(response.json())
print(response.status_code) # 200's when token is invalid {'error': 'invalid token'} in respons
print(response.headers)

0 comments on commit bfcbfb0

Please sign in to comment.