-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_test_token.py
More file actions
58 lines (47 loc) · 1.62 KB
/
Copy pathgenerate_test_token.py
File metadata and controls
58 lines (47 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
"""
Generate a test Clerk JWT token for API testing
"""
import jwt
import time
from datetime import datetime, timedelta
import json
def generate_test_token():
"""Generate a test JWT token that matches Clerk's format"""
# Test user information
user_id = "user_2xy5bIyLFPhOjYUsbJgsUpbjZxL"
email = "test@example.com"
# Current time
now = int(time.time())
# Token payload (similar to Clerk's format)
payload = {
"sub": user_id,
"email": email,
"iss": "https://clerk.example.com", # Issuer
"aud": "your-audience", # Audience
"iat": now, # Issued at
"exp": now + 3600, # Expires in 1 hour
"azp": "your-authorized-party",
"session_id": "sess_test123",
"jti": "jti_test123",
}
# Secret key (for testing only - in production this would be Clerk's key)
secret = "your-test-secret-key-for-development-only"
# Generate JWT
token = jwt.encode(payload, secret, algorithm="HS256")
print("=== Test Clerk JWT Token ===")
print(f"Token: {token}")
print(f"\nUser ID: {user_id}")
print(f"Email: {email}")
print(f"Expires: {datetime.fromtimestamp(payload['exp'])}")
print(f"\nPayload: {json.dumps(payload, indent=2)}")
print("\n=== Usage ===")
print("In Swagger UI:")
print("1. Click 'Authorize' button")
print("2. Enter the token above in the 'Value' field")
print("3. Click 'Authorize'")
print("\nIn curl:")
print(f'curl -H "Authorization: Bearer {token}" http://localhost:8000/api/v1/...')
return token
if __name__ == "__main__":
generate_test_token()