Created
January 9, 2023 15:18
-
-
Save cdracars/f14a1498f4b1280b8b6fba709a28e0aa to your computer and use it in GitHub Desktop.
Generate a JWT token with public/private key python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@router.get("/jwt/token") | |
async def generate_jwt() -> dict[str, bytes] | Literal[False]: | |
"""Returns JWT Token dev work. | |
Returns: | |
Token string or False. | |
""" | |
private_key = load_pem_private_key( | |
bytes(cfg.TOKEN_PRIVATE_KEY, encoding="utf-8"), bytes(cfg.TOKEN_PRIVATE_KEY_PASS, encoding="utf-8") | |
) | |
return { | |
"token": jwt.encode( | |
{ | |
"sub": "MailChimp Notifications", | |
"iss": "iSeries", | |
"exp": 1695243074, | |
# "exp": 1665879026, | |
"iat": 1663272596, | |
"nbf": 1663272596, | |
"jti": "jwt_stuff", | |
}, | |
private_key, | |
algorithm="RS512", | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment