Authentication Mock
Mock authentication and authorization in moclojer - JWT tokens, OAuth flows, API keys, and role-based access control. Test auth without real identity providers.
Learn how to mock authentication and authorization flows for testing without real auth providers.
📋 What You'll Build
✅ JWT token simulation
✅ API key authentication
✅ OAuth 2.0 flow mock
✅ Role-based access control
✅ Session management
🔐 JWT Token Simulation
Login Endpoint
- endpoint:
method: POST
path: /api/auth/login
response:
status: 200
headers:
Content-Type: application/json
body: >
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ7e2pzb24tcGFyYW1zLmVtYWlsfX0iLCJpYXQiOjE2NDAwMDAwMDB9.mock_signature",
"user": {
"id": 123,
"email": "{{json-params.email}}",
"name": "{{json-params.name}}",
"role": "user"
},
"expires_in": 3600
}Protected Endpoint
Unauthorized Response
🔑 API Key Authentication
🌐 OAuth 2.0 Flow
Authorization Endpoint
Token Exchange
👥 Role-Based Access Control
Admin Endpoint
🧪 Complete Auth Flow Example
🚀 Testing Examples
✅ Best Practices
Do ✅:
Simulate realistic token formats
Include proper HTTP status codes (401, 403)
Return meaningful error messages
Test both success and failure scenarios
Don't ❌:
Don't use real passwords or secrets
Don't skip error responses
Don't forget token expiration simulation
📚 See Also
Header Parameters - Auth headers
Error Handling - Auth errors
Stripe Mock Example - API key auth
Real-World Example - Auth simulation
💡 Tip: Use moclojer auth mocks for frontend development, CI/CD testing, and local development without real auth providers!
Last updated
Was this helpful?