Skip to main content
This locustfile demonstrates how to test a complete OAuth 2.0 authorization code flow with PKCE (Proof Key for Code Exchange). This is commonly used by modern web applications and SPAs for secure authentication.

Use Cases

  • Testing OAuth 2.0 providers (Auth0, Okta, Google, etc.)
  • Load testing authentication flows in SPAs
  • Validating OAuth security implementations
  • Testing token refresh mechanisms

Complete Locustfile

Configuration

Before running this test in LoadForge, update these variables:

LoadForge Setup

  1. Upload the locustfile to LoadForge
  2. Configure your target host to point to your application’s API
  3. Set environment variables for sensitive data like client secrets
  4. Choose appropriate user count - OAuth flows can be resource-intensive
  5. Monitor token refresh patterns in the results

Key Testing Scenarios

  • Authorization Flow Performance: How quickly can users complete OAuth login?
  • Token Exchange Latency: Time taken to exchange codes for tokens
  • Refresh Token Behavior: How well does your app handle token refresh under load?
  • Concurrent Authentication: Multiple users authenticating simultaneously
  • Token Expiration Handling: Graceful handling of expired tokens

Security Considerations

  • PKCE Implementation: Protects against authorization code interception
  • State Parameter: Prevents CSRF attacks
  • Secure Token Storage: Tokens are stored securely in memory
  • Token Revocation: Proper cleanup when sessions end

Common OAuth Providers

This pattern works with:
  • Auth0: https://your-domain.auth0.com
  • Okta: https://your-domain.okta.com
  • Google: https://accounts.google.com
  • Microsoft: https://login.microsoftonline.com
  • GitHub: https://github.com/login/oauth

Troubleshooting

  • Invalid Client: Check your client_id configuration
  • Redirect URI Mismatch: Ensure redirect URI matches OAuth app settings
  • PKCE Errors: Verify code challenge generation is correct
  • Scope Issues: Check if requested scopes are allowed for your client
When you add this test to LoadForge, you’ll be able to see detailed metrics on each step of the OAuth flow, helping you identify bottlenecks in your authentication system.