Authentication & Identity
Anchor Browser enables secure connections to services that require authentication, without exposing credentials or cookies directly to the AI agent. This guide covers two supported methods for achieving secure access.
Method 1 (Recommended) - Mounting a Browser Context
In this method, Anchor Browser uses a pre-authenticated browser context to access protected resources. This approach is recommended because it maintains a secure, isolated environment for authentication without exposing sensitive data.
Authenticate Once
Start by logging into the target service in a dedicated browser session. This creates a browser context with the required cookies and session data.
Export Browser Context
Once authenticated, export the browser context (including cookies and session data) and save it securely.
Mount in Anchor Browser
Use the saved browser context within Anchor Browser to access authenticated services seamlessly.
Method 2 - Playwright-Based Cookie Injection
For cases where browser context mounting isn’t feasible, Playwright allows direct injection of cookies into a browser session, enabling access to authenticated resources.
Obtain Authentication Cookies
Authenticate manually or programmatically to capture the required cookies.
Inject Cookies into Playwright Session
Use Playwright’s API to inject cookies into the browser session before navigating to the authenticated page.
Access Resources
With the cookies injected, the AI agent can interact with the protected service as if logged in.
Code example
Secure Storage of Secrets
To maintain the security of your credentials, API keys, and sensitive data, do not store secrets directly in plaintext within your code. Instead, consider these best practices:
- Environment Variables: Store secrets in environment variables. You can use libraries such as dotenv for Node.js to load variables from a .env file.
- Secrets Management Services: Use secure storage solutions like AWS Secrets Manager, Azure Key Vault, or HashiCorp Vault to manage sensitive data securely.