fix(jwt): add jwt encode for test

This commit is contained in:
gc87
2024-06-11 15:33:04 +08:00
parent 6689c31f72
commit 46ba471c9b
+20
View File
@@ -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}")