> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anchorbrowser.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication (OmniConnect)

> Equip your agent with a persistent identity, enabling seamless access to applications without repeated logins

## Overview

Keep **authenticated browser sessions** running for your AI agents and automations.
<br />**Store credentials once** on an identity, and **Anchor re-authenticates automatically** when a session needs it. **Launch a browser with that identity** and your agent **starts already logged in** ready to work on the target site.

```mermaid theme={null}
flowchart LR
  A["Application:<br/>where to log in"] --> B["Auth flow:<br/>Standard guided or custom"]
  B --> C["Identity:<br/>who logs in"]
  C --> D["Browser session:<br/>starts signed in"]
```

Define an **Application** and an **Identity**; attach that identity when you create the session so the browser starts signed in. New applications include a default **Standard authentication** flow (guided browser sign-in with automatic detection of the site's login). Add or customize **Auth Flows**<span id="configure-auth-flow-for-the-application" /> when you need structured credentials or multiple login methods. For end-user sign-in inside your own product, use **[Embedding End-User Authentication UI](/essentials/omniconnect)**.

## Quick Start

<Steps>
  <Step title="Create an Application">
    <CodeGroup>
      ```javascript node.js theme={null}
      import Anchorbrowser from 'anchorbrowser';

      const anchorClient = new Anchorbrowser();

      // Create an application for a target website
      const app = await anchorClient.applications.create({
        name: 'My LinkedIn User',
        source: 'linkedin.com'
      });

      console.log(app.id);
      ```

      ```python python theme={null}
      from anchorbrowser import Anchorbrowser

      anchor_client = Anchorbrowser()

      # Create an application for a target website
      app = anchor_client.applications.create(
          name="My LinkedIn User",
          source="linkedin.com"
      )

      print(app.id)
      ```

      ```bash cURL theme={null}
      curl -X POST "https://api.anchorbrowser.io/v1/applications" \
        -H "anchor-api-key: YOUR_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{"name": "My LinkedIn User", "source": "linkedin.com"}'
      ```
    </CodeGroup>
  </Step>

  <Step title="Configure Auth Flow for the Application">
    Applications you create already include a default **Standard authentication** flow, so you can create identities with the guided browser experience without this step. Use the API here when you need **additional** flows or structured methods—for example `username_password`, `authenticator`, `custom`, or profile-based sign-in.

    <CodeGroup>
      ```javascript node.js theme={null}
      await anchorClient.applications.authFlows.create(app.id, {
        name: 'Email Login with authenticator',
        methods: ['username_password', 'authenticator']
      });
      ```

      ```python python theme={null}
      anchor_client.applications.auth_flows.create(
          application_id=app.id,
          name="Email Login with authenticator",
          methods=["username_password", "authenticator"]
      )
      ```

      ```bash cURL theme={null}
      curl -X POST "https://api.anchorbrowser.io/v1/applications/{app_id}/auth-flows" \
        -H "anchor-api-key: YOUR_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{"name": "Email Login with authenticator", "methods": ["username_password", "authenticator"]}'
      ```
    </CodeGroup>
  </Step>

  <Step title="Create Identity">
    Create an identity with credentials for the application.

    <CodeGroup>
      ```javascript node.js theme={null}
      const identity = await anchorClient.identities.create({
        source: 'https://linkedin.com',
        name: 'John Doe',
        credentials: [{
          type: 'username_password',
          username: 'john@example.com',
          password: 'secret'
        }]
      });

      console.log(identity.id);
      ```

      ```python python theme={null}
      identity = anchor_client.identities.create(
          source="https://linkedin.com",
          name="John Doe",
          credentials=[{
              "type": "username_password",
              "username": "john@example.com",
              "password": "secret"
          }]
      )

      print(identity.id)
      ```

      ```bash cURL theme={null}
      curl -X POST "https://api.anchorbrowser.io/v1/identities" \
        -H "anchor-api-key: YOUR_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{
          "source": "https://linkedin.com",
          "name": "John Doe",
          "credentials": [{
            "type": "username_password",
            "username": "john@example.com",
            "password": "secret"
          }]
        }'
      ```
    </CodeGroup>

    <Tip>
      For end-user self-service authentication in your app, use [Embedding End-User Authentication UI](/essentials/omniconnect).
    </Tip>
  </Step>

  <Step title="Create Authenticated Sessions">
    Use the identity ID to create an authenticated browser session.

    <CodeGroup>
      ```javascript node.js theme={null}
      import Anchorbrowser from 'anchorbrowser';

      const anchorClient = new Anchorbrowser();
      const identityId = "your-identity-id";
      const session = await anchorClient.sessions.create({
          // Recommended settings for authenticated sessions.
          session: {
              proxy: {
                  active: true,
              }
          },
          browser: {
              captcha_solver: {
                  active: true,
              },
              extra_stealth: {
                  active: true,
              }
          },

          // Identity to authenticate with.
          identities: [{ id: identityId }]
      });

      console.log(session.data.id);
      ```

      ```python python theme={null}
      from anchorbrowser import Anchorbrowser

      anchor_client = Anchorbrowser()
      identity_id = "your-identity-id"
      session = anchor_client.sessions.create(
          # Recommended settings for authenticated sessions.
          session={
              "proxy": {
                  "active": True,
              }
          },
          browser={
              "captcha_solver": {
                  "active": True,
              },
              "extra_stealth": {
                  "active": True,
              }
          },

          # Identity to authenticate with.
          identities=[{"id": identity_id}]
      )

      print(session.data.id)
      ```
    </CodeGroup>
  </Step>
</Steps>

## Identity Metadata

You can add custom metadata to identities for filtering and organization. Metadata is a flexible key-value store that allows you to tag identities with custom attributes.

### Creating an Identity with Metadata

<CodeGroup>
  ```javascript node.js theme={null}
  const identity = await anchorClient.identities.create({
    source: 'https://linkedin.com',
    name: 'John Doe',
    metadata: {
      department: 'Engineering',
      role: 'admin'
    },
    credentials: [{
      type: 'username_password',
      username: 'john@example.com',
      password: 'secret'
    }]
  });
  ```

  ```python python theme={null}
  identity = anchor_client.identities.create(
      source="https://linkedin.com",
      name="John Doe",
      metadata={
          "department": "Engineering",
          "role": "admin"
      },
      credentials=[{
          "type": "username_password",
          "username": "john@example.com",
          "password": "secret"
      }]
  )
  ```

  ```bash cURL theme={null}
  curl -X POST "https://api.anchorbrowser.io/v1/identities" \
    -H "anchor-api-key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "source": "https://linkedin.com",
      "name": "John Doe",
      "metadata": {
        "department": "Engineering",
        "role": "admin"
      },
      "credentials": [{
        "type": "username_password",
        "username": "john@example.com",
        "password": "secret"
      }]
    }'
  ```
</CodeGroup>

### Filtering Identities by Metadata

You can filter identities by metadata when listing them for an application:

<CodeGroup>
  ```javascript node.js theme={null}
  const identities = await anchorClient.applications.listIdentities(app.id, {
    metadata: JSON.stringify({ department: 'Engineering' })
  });
  ```

  ```python python theme={null}
  identities = anchor_client.applications.list_identities(
      application_id="4d0cfce6-cf86-43eb-9955-1332941dbbb6",
      metadata=json.dumps({"department": "Engineering"})
  )
  ```

  ```bash cURL theme={null}
  curl -G "https://api.anchorbrowser.io/v1/applications/{app_id}/identities" \
    --data-urlencode 'metadata={"department":"Engineering"}' \
    -H "anchor-api-key: YOUR_API_KEY"
  ```
</CodeGroup>

## Related

<CardGroup cols={3}>
  <Card title="Embedding End-User Authentication UI" icon="window" href="/essentials/omniconnect">
    Let end users connect accounts from your product
  </Card>

  <Card title="Browser Profiles" icon="fingerprint" href="/essentials/authentication-and-identity">
    Alternative approach using browser profiles
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/applications/">
    Applications and Identities endpoints
  </Card>
</CardGroup>
