Testing Authentication
Local Testing
-
Start your server:
-
Expose with ngrok:
-
Add connector in ChatGPT:
- Settings → Connectors → Add Connector
- Use your ngrok URL:
https://xxxxx.ngrok-free.app/mcp
-
Test authentication:
- ChatGPT will prompt for authentication when accessing protected widgets
- Complete the OAuth flow
- Widget will receive authenticated user context
Debug Mode
Enable debug logging to see authentication flow:- Token extraction from Authorization header
- JWKS discovery from issuer
- Token validation errors
- Scope mismatches
Common Issues
”FastMCP auth support not available”
Problem: Authentication dependencies not installed. Solution: Install required packages:“Failed to initialize JWKS”
Problem: Cannot discover JWKS URI from OAuth provider. Solution: Verify yourauth_issuer_url
is correct and accessible:
jwks_uri
.
Check:
- URL is correct
- URL is accessible from your server
- OAuth provider supports OpenID Connect discovery
”Token verification failed”
Problem: JWT token cannot be verified. Possible causes:- Token expired
- Wrong issuer URL
- Missing required scopes
- Audience mismatch
- Invalid signature
- Token
iss
matchesauth_issuer_url
- Token
aud
matchesauth_audience
(if specified) - Token
exp
(expiration) is in the future - Token has required scopes
”401 Unauthorized” in ChatGPT
Problem: ChatGPT shows unauthorized error. Solution: Check that:-
Authorization server is accessible from internet
-
Dynamic client registration is enabled
- Auth0: Settings → Advanced → OAuth → OIDC Dynamic Application Registration
-
At least one login connection is enabled
- Auth0: Authentication → Database or Social connections
-
auth_resource_server_url
matches your public server URL
”User is always None”
Problem: User context is always None in widgets. Possible causes:- Server auth not configured
- User not authenticated in ChatGPT
- Token verification failing
- Server has
auth_issuer_url
andauth_resource_server_url
configured - Widget has
@auth_required
decorator - User completed OAuth flow in ChatGPT
”Missing required scopes” error
Problem: User doesn’t have required scopes. Solution: Assign permissions to user in OAuth provider: Auth0:- Go to User Management → Users
- Select user
- Click Permissions tab
- Assign API permissions
Decorator not working
Problem: Authentication decorator has no effect. Possible causes:- Import error
- Syntax error
- Decorator applied incorrectly
CORS errors
Problem: CORS errors in browser console. Solution: Ensure CORS is properly configured:Audience mismatch
Problem: “Invalid audience” error. Solution: Ensureauth_audience
matches API identifier:
Auth0:
- Go to Applications → APIs
- Copy the Identifier field
- Use as
auth_audience
:
Debugging Tips
1. Check OpenID Configuration
issuer
matches yourauth_issuer_url
jwks_uri
is presentregistration_endpoint
is present
2. Inspect JWT Token
3. Test Token Verification Manually
4. Enable Verbose Logging
5. Check Server Configuration
Production Checklist
Before deploying to production:- HTTPS enabled for
auth_resource_server_url
- Environment variables used for sensitive configuration
- Short-lived tokens configured (15-60 minutes)
- Specific scopes required for each operation
- Audience validation enabled
- Logging configured for authentication events
- Rate limiting implemented (optional)
- User permissions assigned in OAuth provider
- CORS properly configured
- Error handling implemented
- Token expiration handled gracefully
- Monitoring set up for auth failures
Getting Help
If you’re still experiencing issues:- Check logs with DEBUG level enabled
- Verify OpenID configuration is accessible
- Test token verification manually
- Review OAuth provider settings
- Check GitHub Issues for similar problems
- Ask the community on Discord
Next Steps
- Server Configuration - Review server setup
- Providers - Check OAuth provider configuration
- Advanced Topics - Custom verification and security