Skip to main content
Test APIs that require authentication using various methods. k6 supports all common authentication patterns.

Basic Authentication

HTTP Basic Auth encodes credentials in the Authorization header. You can authenticate in two ways:

Method 1: URL-based Authentication

Include credentials directly in the URL:

Method 2: Authorization Header

Manually construct the Authorization 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:
Specify the auth: 'ntlm' parameter to enable NTLM authentication mode.

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

Use hardcoded or environment-based credentials:

API CRUD Operations

Test complete REST API workflows

Correlation & Dynamic Data

Extract and reuse tokens from responses