From 46ba471c9bf72fa3df2f8712147e7dd2df5f9a41 Mon Sep 17 00:00:00 2001 From: gc87 Date: Tue, 11 Jun 2024 15:30:20 +0800 Subject: [PATCH] fix(jwt): add jwt encode for test --- jwt_encode.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 jwt_encode.py diff --git a/jwt_encode.py b/jwt_encode.py new file mode 100644 index 00000000..9c1f96e5 --- /dev/null +++ b/jwt_encode.py @@ -0,0 +1,20 @@ +import jwt # pip install pyjwt +import time + +with open("neuron.key", "r") as f: + private_key = f.read() + +current_time = int(time.time()) +two_years = 60 * 60 * 24 * 365 * 2 +header = {"alg": "RS256", "typ": "JWT"} +payload = { + "aud": "neuron", + "bodyEncode": 0, + "exp": current_time + two_years, + "iat": current_time, + "iss": "neuron", +} +token = jwt.encode(payload, private_key, algorithm="RS256", headers=header).decode( + "utf-8" +) +print(f"Bearer {token}")