JWT 调试器
解码和检查 JWT 令牌的头部、载荷和过期时间。
常见问题
代码实现
import base64, json
def decode_jwt(token: str) -> dict:
parts = token.split(".")
if len(parts) != 3:
raise ValueError("Invalid JWT format")
def decode_part(part):
# Add padding
padded = part + "=" * (4 - len(part) % 4)
decoded = base64.urlsafe_b64decode(padded)
return json.loads(decoded)
return {
"header": decode_part(parts[0]),
"payload": decode_part(parts[1]),
"signature": parts[2],
}
token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyMSJ9.signature"
decoded = decode_jwt(token)
print(json.dumps(decoded["payload"], indent=2))Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.