Files
AIGC/demo/test_jwt.py

30 lines
751 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import requests
import json
# 测试JWT解析
token = "eyJhbGciOiJIUzUxMiJ9.eyJyb2xlIjoiUk9MRV9VU0VSIiwidXNlcklkIjoxLCJ1c2VybmFtZSI6ImFkbWluIiwic3ViIjoiYWRtaW4iLCJpYXQiOjE3NjE2MzYyNDQsImV4cCI6MTc2MTcyMjY0NH0.qZxHDkgSoSRvmMHBFfRdzZYtC55eCKba3VN07lTsFzKXn1hYbupv7boBJDKNOUrRYaH5ougHLFTI5xm059434g"
# 解码JWT payload
import base64
import json
# JWT由三部分组成header.payload.signature
parts = token.split('.')
if len(parts) == 3:
# 解码payload (第二部分)
payload = parts[1]
# 添加padding
payload += '=' * (4 - len(payload) % 4)
decoded = base64.urlsafe_b64decode(payload)
payload_data = json.loads(decoded.decode('utf-8'))
print("JWT Payload:", payload_data)
else:
print("Invalid JWT format")