Basic Authentication
HTTP Basic Auth encodes credentials in theAuthorization header. You can authenticate in two ways:
Method 1: URL-based Authentication
Include credentials directly in the URL:Method 2: Authorization Header
Manually construct theAuthorization header:
The
encoding.b64encode() function base64-encodes the username:password string as required by the Basic Auth specification.Bearer Token Authentication
Common for OAuth 2.0 and JWT-based APIs:Dynamic Token Retrieval
Retrieve tokens during the setup stage:NTLM Authentication
For Windows-integrated authentication:AWS Signature v4
Authenticate requests to AWS APIs using the k6-jslib-aws library:Running with AWS Credentials
For temporary credentials (like from AWS STS), include
AWS_SESSION_TOKEN as an environment variable.Authentication Patterns
- Single User
- Multiple Users
- Token Refresh
Use hardcoded or environment-based credentials:
Related Resources
API CRUD Operations
Test complete REST API workflows
Correlation & Dynamic Data
Extract and reuse tokens from responses