This directory contains Postman collection and environment files for testing the Authentication Middleware API.
Auth_Middleware.postman_collection.json- Complete API collection with all endpoints and tests
Auth_Middleware.postman_environment.json- Development environment (localhost)Auth_Middleware.postman_environment.staging.json- Staging environmentAuth_Middleware.postman_environment.production.json- Production environment
-
Open Postman
-
Import Collection:
- Click "Import" button
- Select
Auth_Middleware.postman_collection.json - The collection will be imported with all endpoints and tests
-
Import Environment:
- Click "Import" button again
- Select the appropriate environment file:
Auth_Middleware.postman_environment.jsonfor local developmentAuth_Middleware.postman_environment.staging.jsonfor stagingAuth_Middleware.postman_environment.production.jsonfor production
-
Select Environment:
- In the top-right corner, select the imported environment from the dropdown
# Navigate to the example service directory
cd example-service
# Install dependencies
npm install
# Start the server
npm startThe server will start on http://localhost:3000 by default.
- Health Check - Verify the server is running
- Login - Authenticate to get cookies
- Test Protected Endpoints - Use the authenticated session
-
Health & Documentation
GET /health- Verify server statusGET /api-docs- Access API documentation
-
Authentication
POST /login- Login with user credentialsPOST /login(Admin Role) - Login with admin credentialsPOST /api/refresh- Refresh access tokenPOST /logout- Logout and clear cookies
-
Public Endpoints
GET /api/public- Test public endpoint (no auth required)
-
Protected Endpoints
GET /api/user- Test user endpoint (requires auth)GET /api/admin- Test admin endpoint (requires ADMIN_ACCESS)GET /api/limited- Test rate-limited endpoint
-
Token Management
POST /api/revoke- Revoke user tokens
-
Error Scenarios
- Test authentication failures
- Test permission denials
baseUrl- API base URL (e.g.,http://localhost:3000)contentType- Request content type (application/json)timeout- Request timeout in milliseconds
csrfToken- CSRF token (auto-generated)accessToken- JWT access token (set by login)refreshToken- JWT refresh token (set by login)
userId/adminUserId- Test user IDsuserEmail/adminEmail- Test email addressesuserRoles/adminRoles- User role arraysuserPermissions/adminPermissions- User permission arrays
- Base URL:
http://localhost:3000 - Timeout: 10 seconds
- Use: For local development and testing
- Base URL:
https://staging-auth-middleware.example.com - Timeout: 15 seconds
- Use: For pre-production testing
- Base URL:
https://auth-middleware.example.com - Timeout: 20 seconds
- Use: For production testing (use with caution)
- Cookies are automatically handled by Postman
- No need to manually set cookie headers
- Authentication state persists across requests
Each endpoint includes tests for:
- ✅ Status code validation
- ✅ Response structure validation
- ✅ Cookie handling verification
- ✅ Error scenario testing
- Access protected endpoints without authentication
- Access admin endpoints without proper permissions
- Test rate limiting functionality
-
"Connection refused" errors
- Ensure the authentication middleware server is running
- Check the
baseUrlenvironment variable - Verify the server is running on the correct port
-
"401 Unauthorized" errors
- Run the "Login" request first to authenticate
- Check that cookies are being set properly
- Verify the server's JWT configuration
-
"403 Forbidden" errors
- Use the "Login with Admin Role" for admin endpoints
- Check user permissions in the login request
- Verify the authorization middleware configuration
-
Test failures
- Check the server logs for detailed error messages
- Verify the response format matches expected structure
- Ensure all required environment variables are set
To enable detailed logging:
- Set
NODE_ENV=developmentin the server environment - Check the server console for detailed request/response logs
- Use Postman's console to view request/response details
- Never commit real tokens to version control
- Use different test data for different environments
- Clear sensitive data after testing
- Use staging environment for integration testing
- Limit production testing to authorized personnel only
For detailed API documentation:
- Start the server
- Visit
http://localhost:3000/api-docs - Explore the interactive Swagger documentation
For issues with the Postman collection:
- Check the server logs for detailed error messages
- Verify environment variables are correctly set
- Ensure the server is running and accessible
- Test with the health check endpoint first