t2m / CLERK_TOKEN_GUIDE.md
thanhkt's picture
implement core api
50a7bf0

Getting Your Clerk Token - Step by Step Guide

πŸ” Your Clerk Configuration

Based on the API response, your Clerk app (poetic-primate-48.clerk.accounts.dev) is configured to only support:

  • βœ… Google OAuth (oauth_google)
  • βœ… Ticket-based authentication (ticket)
  • ❌ Email/Password authentication (not enabled)

🎯 Recommended Method: Browser Console

This is the easiest and most reliable method:

Step 1: Sign in via Google OAuth

  1. Open your browser
  2. Go to: https://poetic-primate-48.clerk.accounts.dev
  3. Click "Sign in with Google"
  4. Complete the Google OAuth flow

Step 2: Get the Token

  1. Once signed in, open Developer Tools (Press F12)
  2. Go to the Console tab
  3. Paste this command and press Enter:
    window.Clerk.session.getToken().then(token => console.log('TOKEN:', token))
    
  4. Copy the token (the long string after "TOKEN:")

Step 3: Test Your API

python test_current_api.py http://localhost:8000/api/v1 YOUR_TOKEN_HERE

πŸš€ Quick Start Scripts

Option A: Use the OAuth Helper

python get_clerk_token_oauth.py

Choose option 2 (Manual browser method)

Option B: Use the Simple Helper

python get_token_simple.py

Choose option 1 (Browser Console Method)

πŸ“‹ Complete Example

  1. Open browser and sign in:

  2. Get token in console:

    window.Clerk.session.getToken().then(token => console.log('TOKEN:', token))
    
  3. Copy the token (looks like: eyJhbGciOiJSUzI1NiIsImtpZCI6Imluc18...)

  4. Test your API:

    python test_current_api.py http://localhost:8000/api/v1 eyJhbGciOiJSUzI1NiIsImtpZCI6Imluc18...
    

πŸ”§ Why Email/Password Didn't Work

The API response showed:

{
  "status": "needs_identifier",
  "supported_first_factors": [
    {"strategy": "ticket"},
    {"strategy": "oauth_google"}
  ]
}

This means your Clerk app is configured to only allow:

  • Google OAuth sign-in
  • Ticket-based authentication (for programmatic access)

Email/password authentication is not enabled in your Clerk dashboard.

🎯 Next Steps

Once you have your token:

  1. Test basic connectivity:

    python test_current_api.py http://localhost:8000/api/v1 YOUR_TOKEN
    
  2. Test video generation:

    python test_video_generation.py --base-url http://localhost:8000/api/v1 --token YOUR_TOKEN --quick
    
  3. Run comprehensive tests:

    python test_video_generation.py --base-url http://localhost:8000/api/v1 --token YOUR_TOKEN
    

πŸ’‘ Pro Tips

  • Tokens expire: You may need to get a fresh token periodically
  • Save your token: The scripts will save it to auth_token.txt for reuse
  • Use the browser method: It's the most reliable approach
  • Check token format: Valid tokens start with eyJ

πŸ†˜ Troubleshooting

If the browser console method doesn't work:

  1. Make sure you're signed in to your app
  2. Check that window.Clerk exists by typing it in console
  3. Try refreshing the page after signing in
  4. Make sure you're on the correct domain

If you get "Clerk not found" errors:

  1. Make sure you're on a page where Clerk is loaded
  2. Try going to the main app page after signing in
  3. Check the Network tab for any Clerk-related requests