Skip to content

Instantly share code, notes, and snippets.

@cdracars
Created January 9, 2023 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdracars/f14a1498f4b1280b8b6fba709a28e0aa to your computer and use it in GitHub Desktop.
Save cdracars/f14a1498f4b1280b8b6fba709a28e0aa to your computer and use it in GitHub Desktop.
Generate a JWT token with public/private key python
@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