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

# Authenticating a user

> Send the user a one-time code, verify it, and get the user id your server creates cards with.

Connecting a user is the first step of Issuing. You send them a one-time code, they read it back, and you receive their `user.id`. Your server names the user with that id when it creates and manages their cards.

Every call on this page is made by your server with your org token as the bearer (see [step 1 of the Quickstart](https://docs.agentcard.com/issuing/quickstart.md#1-get-your-credentials)).

## Send the user a code

By email or phone. `external_user_id` is optional: your own id for the user, returned on webhooks so you can match them up.

```bash theme={null}
curl -X POST https://api.agentcard.sh/api/v2/connect/start \
  -H "Authorization: Bearer $ORG_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com", "external_user_id": "your-internal-id"}'
```

```json theme={null}
{ "object": "connect_attempt", "connect_id": "ca_9k1m4x7d", "channel": "email" }
```

## Verify the code

In sandbox the code is always `111111`.

```bash theme={null}
curl -X POST https://api.agentcard.sh/api/v2/connect/verify \
  -H "Authorization: Bearer $ORG_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"connect_id": "ca_9k1m4x7d", "code": "111111"}'
```

```json theme={null}
{
  "object": "connection",
  "access_token": "act_1a2b3c…",
  "refresh_token": "rct_4d5e6f…",
  "token_type": "Bearer",
  "expires_in": 3600,
  "user": { "id": "usr_7g8h9i", "email": "user@example.com", "phone": null }
}
```

Store `user.id`. It is how your server names the user on `/api/v2` calls, always with your org token. The `connection.created` webhook fires here.

## Record consent

Once per user, before you create their first card:

```bash theme={null}
curl -X POST https://api.agentcard.sh/api/v2/connect/consent \
  -H "Authorization: Bearer $ORG_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"user_id": "usr_7g8h9i"}'
```

## Refresh the connection

The card endpoints don't need the `access_token`, so you can skip this step if your server does everything. If you also connect an agent to the [MCP server](https://docs.agentcard.com/tools/mcp.md), its token expires after one hour. Rotate it with the refresh token, using your org token as the bearer:

```bash theme={null}
curl -X POST https://api.agentcard.sh/api/v2/connect/refresh \
  -H "Authorization: Bearer $ORG_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"refresh_token": "rct_4d5e6f…"}'
```

Each refresh returns a new pair and invalidates the old one. Store what comes back. An `invalid_refresh_token` means it was already used or expired: reconnect the user.

## Users you know by phone only

## Sandbox

Sandbox sends email but not SMS, and the code is always `111111`. Sandbox users are isolated: connecting `anyone@example.com` in sandbox can never touch a real account.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.