Skip to main content

Overview

Pensar Apex includes a specialized AuthenticationAgent that handles complex authentication flows automatically. It supports:
  • Form-based authentication (username/password POST)
  • JSON API authentication (REST API login)
  • HTTP Basic/Bearer authentication
  • OAuth 2.0 flows (authorization code, implicit, device code)
  • Browser-based authentication (SPAs, JavaScript-rendered forms)
  • Email verification (automated inbox checking)
  • Multi-factor authentication (when possible)
  • CSRF token handling
The authentication agent operates fully autonomously—no human intervention required. It discovers login endpoints, handles redirects, extracts session cookies, and exports credentials for downstream testing.

Quick Start

1

Provide Credentials to Apex

During session creation, pass authentication credentials:
2

Run Authentication Agent

3

Use Authenticated Session

After successful authentication, the session contains exportable cookies and headers:

How Authentication Works

Credential Management

Apex uses a CredentialManager to securely handle credentials without exposing raw passwords to the AI:
When the agent needs to use credentials, it references them by ID:
The AI never sees raw passwords. Credentials are resolved server-side during tool execution.

Authentication Flow

The AuthenticationAgent follows a deterministic strategy:
1

Detect Auth Mechanism

If no loginUrl is provided, the agent probes the target:
Indicators:
  • 401/403 → API authentication
  • 302 redirect to /login → Form-based auth
  • WWW-Authenticate header → HTTP Basic/Bearer
  • JSON error → REST API auth
2

Attempt Authentication

Based on detection, the agent tries:API Path:
Browser Path (for SPAs/OAuth):
3

Validate Session

After authentication, the agent validates the session:
If successful, returns user data. If 401, auth failed.
4

Export Credentials

The agent calls complete_authentication to persist credentials:
This writes auth-data.json to the session directory for reuse.

Authentication Methods

Form-Based Authentication

For traditional HTML login forms:
Apex will:
  1. POST credentials to the login form endpoint
  2. Extract session cookies from Set-Cookie headers
  3. Validate the session by making an authenticated request

JSON API Authentication

For REST APIs:
Apex will:
  1. POST JSON: {"email": "user@example.com", "password": "password123"}
  2. Extract bearer token from response: {"token": "eyJhbGc..."}
  3. Export header: {"Authorization": "Bearer eyJhbGc..."}

Browser-Based Authentication (SPAs)

For single-page apps with JavaScript-rendered forms:
Apex will:
  1. Launch a headless browser with Playwright
  2. Navigate to the login page
  3. Fill the form fields using accessibility tree refs
  4. Click the submit button
  5. Extract cookies (including httpOnly)
  6. Extract tokens from localStorage/sessionStorage
Browser automation is automatic—Apex detects when JavaScript rendering is required.

OAuth 2.0 Flows

For OAuth providers:
Apex will:
  1. Navigate to the OAuth authorization URL
  2. Fill consent form if needed
  3. Handle redirect back to the app
  4. Extract authorization code from URL
  5. Exchange code for access token
  6. Export bearer token for API requests
OAuth consent barriers (like “Allow access?”) are handled automatically when possible. If a CAPTCHA is present, the agent will report failure.

Email Verification

For flows that require email confirmation:
Apex will:
  1. Register a new account
  2. Use email_search_messages to find the verification email
  3. Extract the verification link from the email body
  4. Navigate to the link to confirm the account
  5. Log in with the verified credentials
Email verification is fully automated using the Gmail or Outlook adapter. See Email Tools below.

Authentication Tools

The AuthenticationAgent has access to these specialized tools:

API Authentication

authenticate_session

Performs credential-based authentication:
Returns:

Browser Authentication

browser_navigate

Loads a page in the headless browser:

browser_snapshot

Captures the accessibility tree with element refs:
Always call browser_snapshot before browser_fill or browser_click to get fresh element refs.

browser_fill

Fills a form field using its ref:
The credential is resolved securely—the AI never sees the raw value.

browser_click

Clicks a button or link:

browser_get_cookies

Extracts all cookies (including httpOnly):

browser_evaluate

Runs JavaScript to extract tokens:

Email Verification Tools

When emailInboxes are configured in the session:

email_list_inboxes

Lists available email inboxes:

email_search_messages

Searches for emails matching a query:

email_get_message

Fetches full email content:

Completion Tools

complete_authentication

Persists authentication data for downstream agents:
This writes ~/.pensar/sessions/<session>/auth/auth-data.json:

Auth Barriers

The agent detects and reports authentication barriers: When a barrier is encountered:
CAPTCHA and MFA are reported as failures—Apex operates autonomously and cannot solve human challenges.

Best Practices

1. Use Credential Manager (Automatic)

Always provide credentials via authCredentials in the session config:

2. Provide Auth Hints

Help the agent by providing hints when known:

3. Review Auth Data

After successful authentication, review the exported data:
Ensure:
  • Cookies are present and valid
  • Headers include bearer tokens if needed
  • Strategy matches the expected auth method

4. Test Authenticated Endpoints

Use the exported credentials for subsequent testing:

Examples

Testing OAuth Flow

Testing Email Verification

Next Steps

Blackbox Testing

Test authenticated endpoints with blackbox testing

Whitebox Testing

Analyze authentication logic in source code

Docker Setup

Run authenticated tests in the Kali container

vLLM Setup

Use local models for authentication testing