# Let people connect their accounts

Your agents act for the people who chat with them: on your own servers, and on other services, each time with the
person's own account there. Each person connects an account once, the first time an agent needs it, and the connection
is kept and renewed. This guide explains what a person meets as they connect, how your agents know your people, what
your own MCP server does so your people can connect to it, and how to set it all up, in your console and at your
identity provider.

The words this guide uses, as your console uses them:

- **Your identity provider** is the OpenID Connect issuer your app's people sign in with, such as Auth0, Okta or
  Keycloak. An app with none makes a **signing key** instead (HS256, a shared secret), which its own server signs their
  tokens with. You add either in your console, under Access → Single sign-on, in Embed sign-in.
- **A person** is someone who chats with your agents: a user, who is signed in to your app, or a visitor, who isn't.
- **A connector** is a server that gives your agents tools (an MCP server): one of your own, or a third party's. You
  add it in your console, under Build → Connectors.
- **To connect** is a person signing in to a connector's server with their own account there. The connection is kept
  and renewed (OAuth), and the agents use it in every conversation after.
- **Your MCP server** is a server of yours that signs people in with your identity provider, as MCP's authorization
  describes, so its tools act for each person with their own account.
- **The embed code** is the lines on your page that put the chat there and hand it each signed-in person's token.

## What a person meets

A person connects an account on a connector that signs in with each user's own login (Add it as a connector, below):
every call runs as the person who sent the turn, with their own account at the server. When a turn needs an account
its person hasn't connected, the chat, on your site or in your chat app, pauses the turn and shows a card:

- **"Connect {connector}"**, the first time;
- **"Sign in to {connector} again"**, once a connection stopped working, such as when the person removed your agents'
  access at the service.

The card opens a window, which goes on to the server's sign-in, and says "Sign in in the window that opened. The agent
goes on once you're connected." The person signs in there with their own account, and allows your agents' access where
the server asks. The window then says their account is connected, and the agent goes on in the chat. "Not now" tells
the agent they chose not to.

**No password where they're signed in already.** The window is the server's sign-in, in the person's own browser. When
that browser is signed in there already, the sign-in asks for no password: at most it asks them to allow your agents'
access, and the window goes on. Your people are signed in at your identity provider once they've signed in to your app
through its page, so a connect to your own MCP server, which signs them in there, takes them straight through (Your own
MCP server, below). When your app has a login form of its own, the first connect asks for their password once, and
your identity provider's session covers the rest. At a third party's service, they sign in with their account there.

Only that window can finish the connect. The chat hands it a one-time binding as it opens it, and the sign-in finishes
only with that binding (as RFC 9700 binds a flow to the browser that started it). A copy of its address, opened
anywhere else, connects nothing: its page says "Open this from your chat", or that the link is no longer open. So
someone sent a person's link can't connect their own account to that person's chat.

The binding needs the browser's Web Crypto (`crypto.subtle`), which a page served over plain http doesn't have. Serve
the pages your chat is on over https. `http://localhost` works while you develop.

In your console's Playground, a connector on each user's own login connects your own account, as you test.

### Through the API

When a turn of an API conversation needs an account, it pauses with a `chat:connect` interrupt. Its
`metadata.chat.url` is a link for the person. Open it for that person alone, in a window of its own.

The link's page says whose chat it's for, by the name your app gave the person: "You're connecting an account to
{person}'s chat with {agent}". It goes on when they choose Continue, and binds the sign-in to its own window, as the
chat does. That page is the guard against the link reaching someone else, who would connect their own account to the
person's chat. Keep the link as private as the conversation.

Once they've connected, the turn goes on by itself, and the conversation's stream shows it. There's nothing to resume.

### A person's connections

The chat's menu lists a person's accounts under Connected accounts: the ones they connected, with the account each
signed in as where its sign-in named it, and the ones the agent connects for them that they haven't yet. They connect
one there with "Connect {connector}", or with "Reconnect {connector}" once it says "Sign in again next time", and can
disconnect any. Your chat app's Settings lists them too, across agents.

Your server lists and removes them with your API key: `GET /users/{id}/connections` and
`DELETE /users/{id}/connections/{connector}`, and the same under `/visitors/{id}`. `GET /users/{id}/connectors` lists
the accounts an agent connects for the person, and `POST /users/{id}/connections/{connector}/link` gives your app a link
for them to connect one from its own menu, through a page like the interrupt's. An agent that needs a connection
removed asks for it again.

## How your people are known

Every person who chats with your agents is a user or a visitor. Each has one record of their own, which holds their
conversations, their files and the accounts they connected. No call for one person reaches another's.

A user is someone signed in to your app. They're known by the ID your app gives them, however they arrive:

- **In the embed**, your page hands the chat their token. An identity provider that keeps a token in the page takes one
  line of script, `getUserToken`. A session behind a cookie takes one attribute, `token-url`. The chat checks the token
  against your identity provider, or your signing key, and reads the person's ID from its `sub` claim, or from the claim
  you choose in Embed sign-in, which fills in Okta's `uid` and Entra ID's `oid` itself, since their `sub` isn't the one
  ID a person keeps.
- **Through the API**, your server names them with `X-User-ID`.

One ID is one person. A token naming `4711` and `X-User-ID: 4711` are the same user, with the same conversations and the
same connected accounts. So every identity provider you add must name people by your app's IDs. Add token issuer says so
when you add a second one: "Its people's IDs must be your app's IDs. If they're different people, they'd share
conversations."

A token is checked before the person chats, and asked for again before the session it made ends. It's never stored.
It also tells the agent the person's name, email, language and time zone, from the claims Embed sign-in reads them from:
`name`, `email`, `locale` and `zoneinfo`, unless you choose others. Your server tells the agent the same through the
API, with `PUT /users/{id}`.

A visitor isn't signed in. The embed makes an ID for each visitor the first time they chat, and their browser keeps it
until 30 days after their last visit. Your server names a visitor through the API with `X-Visitor-ID`. A visitor
connects no accounts of their own (Visitors don't connect accounts, below).

In your console, under Access → Single sign-on, Embed sign-in lists what your page's tokens are checked against: your
identity provider, or a signing key. Add yours there, then your page's embed code. Each step is below; each identity
provider's own is under Each provider's setup.

### Your identity provider

1. Under Embed sign-in, choose **Add token issuer**.
2. Give one of these: your identity provider's domain, such as `acme.us.auth0.com`; its address (its issuer); its
   discovery address, ending in `/.well-known/openid-configuration`; or a token your app got from it. For one that
   publishes no discovery document, choose **Enter endpoints manually** and give its issuer and its JWKS URI.
3. Its discovery document is read (OpenID Connect Discovery, else RFC 8414's authorization server metadata), and the
   line under the field says what was found. One that publishes no key to check your people's tokens with can't be
   added.
4. A token you paste is read and checked, never kept. Its audience and claims fill in the form, and the line says whom
   it names, such as "This token checks: it names Ana Ruiz, user 4711."
5. Give the audience: the app your page's tokens are for. A token is judged by its `aud`, which must hold it; a token
   with no `aud`, by its `azp`; one with neither, by its `client_id`. A token for another of your identity provider's
   apps opens no session, and an identity provider with no audience takes none.
6. Check which claims hold the person's ID (`sub` unless you choose another), and their name, email, language and time
   zone.
7. Choose **Add token issuer**.

Its document and keys are read again every day. Each token issuer in the list says the audience it takes, when it last
accepted a token, and why it last refused one.

### Embed code

Your page hands the chat each signed-in person's token in one of two ways:

- **One line of script**, for an identity provider that keeps a token in the page: `getUserToken`, a function that
  answers the token. Your identity provider's line is under its name in Each provider's setup, and in your console on
  each agent's embed, under Deliver → Embed.
- **One attribute**, for a session behind a cookie: `token-url`, a path on your own origin that answers the token.

The lines are for a page where the person is signed in. Where someone may not be, answer `null` for them: an error
counts as no one too, but the chat warns about it in the browser's console each time it asks.

Add `token-url` to your chat's element, naming a path on your page's own origin, and keep the element's other
attributes, such as `mode="bubble"`:

```html
<agent-chat agent="YOUR_AGENT_ID" token-url="/chat-token"></agent-chat>
```

The chat reads that path with your page's cookies, never cached: as it starts, before the session it made ends, and
after a refusal.

- Answer the person's token as plain text, or as JSON: `{"token": "…"}`.
- When no one is signed in, answer `200` with nothing, or `{"token": null}`. An error status, such as `401`, counts as
  no one too, but the chat warns about it in the browser's console each time it asks, and JSON with no `token` in it
  counts as no one with a warning once.
- It reads only a path on your page's own origin, its scheme, host and port. An address anywhere else, another
  subdomain of your site included, is ignored, with a warning in the browser's console. An answer your server sends on
  to another origin counts as no one.
- When your page also sets `getUserToken`, the chat asks that instead.

Your server answers with a token your identity provider gave it, while it's fresh, or one it signs with a signing key (A
signing key, below).

The `token-url` line names the agent by its ID, `YOUR_AGENT_ID` here: the agent's Embed in your console gives it with
its own ID filled in. [Put an agent on your site](https://hados.io/api/docs/embed) shows each form of the chat.

### A signing key

For an app with no identity provider, such as one with sessions behind a cookie: choose Make a signing key under Access
→ Single sign-on, in Embed sign-in. Your server signs a token for each signed-in person with it, and your page names
that server's path with `token-url` (Embed code, above). The server's lines, in five languages, are in [Put an agent on
your site](https://hados.io/api/docs/embed).

A signing key signs your people in to your chat alone. A connector's server signs them in with an identity provider of
its own, where each person connects once.

## Your own MCP server

An MCP server of yours can act for each person with their own account. It signs people in with your identity provider,
as MCP's authorization describes (its 2026-07-28 revision), and your agents connect each person to it the first time
they need it. A person whose browser is still signed in at your identity provider, as it is once they've signed in to
your app through its page, connects with no password (What a person meets, above). This section says what your server
and your identity provider serve for that, and what a connect sends them. A third party's server is connected the same
way, by what it serves.

### Add it as a connector

Under Build → Connectors, choose Add a connector and give your server's MCP address. Your console asks the server what
it offers, then one question: "How does the agent sign in to this server?" It offers the choices the server takes, in
this order. Each user's own login comes first, chosen for you:

- **Each user's own login (Per-user OAuth)**: "Calls run as the person chatting." Every call runs as the person who
  sent the turn, with their own account at the server. The first call for someone who hasn't connected pauses the turn
  and asks them to connect. The turn goes on once they have. On their own account, each person decides which actions
  ask them first.
- **One shared account (Shared OAuth)**: "An owner or a manager signs in once; every chat uses it." Every person's
  calls go through that account alike.
- **API key**, or **No authentication**. These are shared too, and nobody connects.

On a shared one, your agent's builder decides which actions ask the person first.

Below the choices, Advanced: OAuth client says which OAuth client the connector signs in with (Its OAuth client,
below), and the scopes it asks for. Then turn the connector on in an agent's Connectors tab.

### Its metadata

Your server names your identity provider as its authorization server in its protected-resource metadata (RFC 9728), as
MCP's authorization asks:

- `resource`: your server's address, the MCP address you add it by, or a path above it, such as its origin;
- `authorization_servers`: your identity provider's issuer. When it lists several, a connector keeps the one it already
  signs in at, else takes the first;
- `scopes_supported`: the scopes your tools need for everyday use.

Serve it at `/.well-known/oauth-protected-resource` followed by your MCP endpoint's path, such as
`https://mcp.acme.com/.well-known/oauth-protected-resource/mcp` for `https://mcp.acme.com/mcp`, or at the root,
`https://mcp.acme.com/.well-known/oauth-protected-resource`, and name it in your 401s (Its challenges, below). Your
console reads it as you add the connector: it calls your server with no token, and follows your 401 to it.

Your identity provider's own metadata is read again at every connect, at RFC 8414's address
(`/.well-known/oauth-authorization-server`) or OpenID Connect's (`/.well-known/openid-configuration`). Its `issuer` is
the one your server names. A connect reads these in it:

| It lists | So a connect |
| --- | --- |
| `S256` in `code_challenge_methods_supported` | Proves its code with PKCE. MCP requires it: a connect refuses an identity provider that doesn't list it |
| `client_id_metadata_document_supported`, and `none` in `token_endpoint_auth_methods_supported` | Can sign in with a client document (Its OAuth client, below) |
| `registration_endpoint` | Can register a client (Its OAuth client, below) |
| `openid` in `scopes_supported` | Asks for it, and for `profile` and `email` where each is listed, beside your server's scopes, so the connection shows the account's name. A connect that asks no scope of its own asks none of the three |
| `offline_access` in `scopes_supported` | Asks for it, so the connection renews |
| `authorization_response_iss_parameter_supported` | Refuses an answer that doesn't name its issuer (The sign-in, below) |

An identity provider without `S256` still checks your people's tokens for the embed, but a server that signs people in
there can't act for each person: add it with an API key.

### Its OAuth client

Every connect needs an OAuth client at your identity provider: the app your people allow there. A connector signs in
with the first of these it has:

1. **Its own OAuth client**, one you make at your identity provider for your agents. Enter it under Advanced: OAuth
   client as you add the connector, where it's "Optional: registered with the provider for this connector alone, and
   used before any other.", or later in the connector's Settings. Advanced: OAuth client then names it: "Its own OAuth
   client, registered with the provider." One client can serve every connector at one identity provider: enter it on
   each.
2. **A client document** (OAuth Client ID Metadata Documents), where your identity provider lists
   `client_id_metadata_document_supported` and takes a client with no secret, `none` among its
   `token_endpoint_auth_methods_supported`: a document's client is public. It carries your name and icon, as your
   console holds them, and both redirect addresses (below). Its address is on your console's host: an identity provider
   that takes documents only from the domains it trusts must trust that one.
3. **A registration** (Dynamic Client Registration, RFC 7591), where your identity provider offers one: a client named
   for you, registered at the first connect and kept. MCP keeps registration for identity providers that take no client
   documents, and most identity providers refuse it until you turn it on there.
4. **None**: Advanced: OAuth client says "None: enter your OAuth client below.", and says the client is needed, "so
   enter your OAuth client here". The connector isn't added without one: "that server's login needs an OAuth client
   registered with its provider: enter its client ID and secret under Advanced: OAuth client".

A client you make allows the authorization code grant with PKCE, refresh tokens, both redirect addresses and the scopes
your servers ask for, with `offline_access`, and `openid`, `profile` and `email` where your identity provider lists
them. Usually it's a confidential client, with a secret; one with no secret is public. Each identity provider's steps
are under Each provider's setup. A new client means everyone signs in again: the connections made through the old one
go.

### The redirect addresses

A connect comes back to one of two addresses, which a client you make allows as its redirect URIs. Advanced: OAuth
client shows both, to copy: "Register both redirect URIs with the provider: the console's, and the API's, where your
people connect from their chats."

- `https://hados.io/api/v1/connect/callback`, for your people, who connect from their chats: on your site, in your chat app,
  and through the API's links;
- your console's own, ending in `/connections/callback`, for your team, who connect in your console: on a connector's
  page and in the Playground.

A connector on one shared account comes back to your console's alone. A client document and a registration list both
by themselves.

### The sign-in

Each connect is OAuth's authorization code flow, as MCP's authorization has it:

- **PKCE**, with the `S256` challenge, so only the connect that started a sign-in can use its code.
- **`resource`** (RFC 8707): your server's `resource`, as its metadata names it, in the sign-in and in the token
  request. Your identity provider issues the token for your server, and your server accepts only tokens issued for it,
  as MCP requires.
- **The scopes**: those your server's 401 names in its challenge, else its metadata's `scopes_supported`, as Advanced:
  OAuth client lists them; beside them, `openid` where your identity provider lists it, with `profile` and `email` where
  each is listed, so the connection shows the account's name from the ID token: its email, else its name, else its
  `preferred_username`; and `offline_access` last, where your identity provider lists it, so the connection renews. A
  connect that asks no scope of its own, as for a server that names none, asks none of the three: MCP's rule asks such
  a server for no scope, `offline_access` aside, and `openid` would replace your identity provider's default scopes.
  Leave `offline_access` out of your server's own scopes: a connect adds it where your identity provider lists it.
  Signing in again also asks what a connect asked for the person's connection before and your identity provider
  granted, so it keeps what it had; a name your identity provider added to its answer on its own isn't asked back. A
  connect for more access (Its challenges, below) asks the scopes your 403 names too.
- **`state`**, used once: a sign-in finishes within 10 minutes of its start, in the window that started it.
- **`iss`** (RFC 9207): when your identity provider names itself in its answer, the `iss` must be exactly the `issuer`
  its metadata names, a final slash and all. An answer naming another connects nothing. Where its metadata says it
  names itself (`authorization_response_iss_parameter_supported`), an answer without `iss` connects nothing either.

A connection keeps its tokens, which no one is shown and no agent reads. It's renewed with its refresh token before it
ends, and when your server refuses its token. When the person disconnects, its tokens are revoked where your identity
provider offers revocation.

### Its challenges

Your server takes each person's token in `Authorization: Bearer …`, and says why it refuses one in `WWW-Authenticate`,
as MCP's authorization has it:

- **`401 Unauthorized`**, for a request with no token, or with one that's expired, revoked or not issued for your
  server: a challenge naming your metadata, and in `scope` the scopes the request needs, such as
  `WWW-Authenticate: Bearer resource_metadata="https://mcp.acme.com/.well-known/oauth-protected-resource/mcp", scope="orders:read"`.
  A connection whose token meets a 401 is renewed once; one still refused asks its person to sign in again, with "Sign
  in to {connector} again".
- **`403 Forbidden`**, for a good token that lacks a scope the request needs: `error="insufficient_scope"`, every scope
  the request needs in one `scope`, and your metadata, such as
  `WWW-Authenticate: Bearer error="insufficient_scope", scope="orders:read orders:write", resource_metadata="https://mcp.acme.com/.well-known/oauth-protected-resource/mcp"`.
  Keep 401 for a token that's no good: a missing scope is a 403. The person is asked to allow more access, with "Sign
  in to {connector} again", and that sign-in asks your connector's scopes, what was asked for their connection before
  and granted, and those your challenge names. The call goes on once they have; a call asks once, so one your server
  still refuses then ends.

## Each provider's setup

Each identity provider's own setup, in its own console's words: what Embed sign-in takes from it and your embed code,
for your people's tokens; then, for your MCP servers that sign people in there, how a connect gets its OAuth client.
Where a provider takes neither a client document nor a registration, make one client there for your agents, as below,
and enter it as each such connector's own, under Advanced: OAuth client. Both redirect URIs are the two addresses in The
redirect addresses, above.

### Auth0

Give Embed sign-in your Auth0 domain, such as `acme.us.auth0.com`, or your custom domain. Its audience is your API's
Identifier, under Applications → APIs. Give your page's Auth0 client the same `audience`, so `getTokenSilently()`
answers a signed token rather than an opaque one.

Your embed code, which renews the token when it's due:

```js
const chat = document.querySelector('agent-chat')
chat.getUserToken = () => auth0.getTokenSilently()
```

Auth0 refuses an app that registers itself until you turn on Dynamic Client Registration, under Settings → Advanced,
which is off at first. Make a client for your agents instead, in the Auth0 Dashboard:

1. Go to Applications → Applications and choose Create Application.
2. Name it (Agents, say), choose Regular Web Applications, and create it.
3. On its Settings tab, paste both redirect URIs into Allowed Callback URLs, and save.
4. Under Advanced Settings → Grant Types, keep Authorization Code and Refresh Token on.
5. If your servers' tokens are for an Auth0 API, turn on Allow Offline Access in Applications → APIs → that API →
   Settings, so connections renew.
6. Copy the Client ID and Client Secret from its Settings tab into each connector's Advanced: OAuth client.

### Okta

Give Embed sign-in your custom authorization server's address, such as `https://acme.okta.com/oauth2/default`. Custom
authorization servers come with Okta's API Access Management. Your org's own, `https://acme.okta.com`, won't do: its
access tokens are for Okta's own APIs, and others can't check them. Its audience is the authorization server's, under
Security → API → Authorization Servers: `api://default` for the default one.

Embed sign-in reads the person's ID from `uid` in your page's tokens, and from `sub` in ID tokens. Both are the Okta
user ID, which never changes; an Okta access token's `sub` is the person's login, which can. For an identity provider
you add now, there's nothing to set up for it. One added before Embed sign-in filled these in keeps `sub`, the login, as
the person's ID; adding it again fills them in, and names its people anew, by their user ID.

Your embed code, which renews the token when it's due:

```js
const chat = document.querySelector('agent-chat')
chat.getUserToken = () => oktaAuth.getOrRenewAccessToken()
```

Okta registers an app only for a caller with an API token, which your agents don't have. Make a client for your agents,
in the Okta Admin Console:

1. Go to Applications → Applications and choose Create App Integration.
2. Choose OIDC - OpenID Connect and Web Application, then Next.
3. Name it, tick Refresh Token beside Authorization Code, and paste both redirect URIs into Sign-in redirect URIs.
4. Under Assignments, choose who may use it, and save.
5. In Security → API → Authorization Servers, open the server your servers use, and check that an access policy rule
   lets this client in, with the scopes your servers ask for and `openid`, `profile` and `email`: a rule applies only
   when it allows every scope a connect asks.
6. Copy the Client ID and Client secret from its General tab into each connector's Advanced: OAuth client.

### Entra ID

Give Embed sign-in your own tenant's address: `https://login.microsoftonline.com/YOUR_TENANT_ID/v2.0`. The `common` and
`organizations` addresses name no one issuer, so Embed sign-in refuses them.

In your API's app registration, open Manifest and set `requestedAccessTokenVersion` to `2` (`accessTokenAcceptedVersion`
in the older manifest). Its access tokens then name the issuer Embed sign-in read, ending in `/v2.0`, and hold your
API's Application (client) ID as their audience. Give Embed sign-in that ID as the audience.

Embed sign-in reads the person's ID from `oid`, and fills that in itself: Entra ID's `sub` is different in each app,
while `oid` is the same person in every app of your tenant.

Your embed code, with your API's scope. MSAL renews the token when it's due. It needs the signed-in account set as its
active account (`msal.setActiveAccount`), to know whose token to get:

```js
// Your API's scope, as Expose an API shows it in its app registration
const chat = document.querySelector('agent-chat')
chat.getUserToken = async () => {
  const result = await msal.acquireTokenSilent({
    scopes: ['YOUR_API_SCOPE'],
  })
  return result.accessToken
}
```

Entra ID can be your identity provider for the embed, but your MCP servers can't sign people in through it: its
discovery document doesn't list PKCE's S256, which MCP requires. A server that signs people in there can't act for each
person: add it with an API key.

### Keycloak

Give Embed sign-in your realm's address, such as `https://sso.acme.com/realms/acme`. Its audience is the client an
Audience mapper puts in your tokens, set in your app client's dedicated client scope.

Your embed code, which renews the token first when it ends within 30 seconds:

```js
const chat = document.querySelector('agent-chat')
chat.getUserToken = async () => {
  await keycloak.updateToken(30)
  return keycloak.token
}
```

Keycloak's Trusted Hosts policy refuses an app that registers itself, unless its request comes from a host you trust.
Make a client for your agents instead, in the Keycloak Admin Console:

1. Choose your realm, go to Clients and choose Create client.
2. Keep OpenID Connect, give it a Client ID (agents, say), and Next.
3. Turn on Client authentication, keep Standard flow on, and Next.
4. Paste both redirect URIs into Valid redirect URIs, and save.
5. On its Client scopes tab, choose Add client scope, and add the scopes your servers ask for as Optional. Create any
   that are missing under Client scopes in the menu. Keycloak refuses a scope its client wasn't given, so keep
   `profile` and `email`, which a new client has: a connect asks them.
6. Copy the Client ID, and the Client Secret from its Credentials tab, into each connector's Advanced: OAuth client.

### Cognito

Give Embed sign-in your user pool's address, such as `https://cognito-idp.us-east-1.amazonaws.com/us-east-1_EXAMPLE`.
Its audience is your app client's ID, which Cognito's ID tokens hold. Its access tokens hold no audience, so your page
hands over the ID token.

Your embed code, here with Amplify, which renews the session's tokens when they're due:

```js
// With Amplify: import { fetchAuthSession } from 'aws-amplify/auth'
const chat = document.querySelector('agent-chat')
chat.getUserToken = async () => {
  const { tokens } = await fetchAuthSession()
  return tokens?.idToken?.toString()
}
```

Cognito can be your identity provider for the embed, but your MCP servers can't sign people in through it: its
discovery document doesn't list PKCE's S256, which MCP requires. A server that signs people in there can't act for each
person: add it with an API key.

### Clerk

Give Embed sign-in your Frontend API's address, such as `https://clerk.acme.com`, or `https://NAME.clerk.accounts.dev`
while you develop. Its audience is your site's address, its origin, such as `https://acme.com`: Clerk's session tokens
carry no `aud`, and name the site that asked for them in `azp`. With a JWT template that adds an `aud`, such as Convex's
`convex`, its audience is what that `aud` holds, since a token with an `aud` is judged by it alone. Its session tokens
last 60 seconds, and the chat asks for a new one before each ends.

Your embed code:

```js
const chat = document.querySelector('agent-chat')
chat.getUserToken = () => Clerk.session.getToken()
```

Clerk refuses an app that registers itself until you turn on Publish DCR support, under OAuth applications → Settings,
which is off at first. Make a client for your agents instead, in the Clerk Dashboard:

1. Go to OAuth applications and add an OAuth application.
2. Name it and choose the scopes your servers ask for, offline_access, and openid, profile and email.
3. Copy its Client Secret now: Clerk shows it once.
4. On its page, add both redirect URIs as Redirect URIs, and keep Public off.
5. Copy the Client ID from its Application credentials, and the secret, into each connector's Advanced: OAuth client.

### Supabase

Give Embed sign-in `https://PROJECT_REF.supabase.co/auth/v1`, with your project's reference. Its tokens are checked
against the keys your project publishes, which it does once it signs with asymmetric JWT signing keys. A project still
on the legacy shared secret publishes none, so it can't be added. Its audience is `authenticated`, which every Supabase
session token holds.

Your embed code:

```js
const chat = document.querySelector('agent-chat')
chat.getUserToken = async () => {
  const { data } = await supabase.auth.getSession()
  return data.session.access_token
}
```

Supabase refuses an app that registers itself until you turn on dynamic client registration, under Authentication →
OAuth Server, which is off at first. Make a client for your agents instead, in your Supabase project's dashboard:

1. Turn on the OAuth server in Authentication → OAuth Server.
2. Go to Authentication → OAuth Apps and choose Add a new client.
3. Name it, add both redirect URIs as Redirect URIs, choose Confidential as its Client type, and create it.
4. Copy the Client ID and Client Secret into each connector's Advanced: OAuth client: the secret is shown once.

### Firebase

Give Embed sign-in `https://securetoken.google.com/PROJECT_ID`, with your project's ID. Its audience is that ID, which
every Firebase ID token holds.

Your embed code:

```js
const chat = document.querySelector('agent-chat')
chat.getUserToken = () => firebase.auth().currentUser.getIdToken()
```

Firebase signs no other apps in, so your MCP servers can't sign people in through it.

### Logto

Give Embed sign-in your Logto tenant's address, such as `https://acme.logto.app/oidc`, or just `acme.logto.app`. A
custom domain is an issuer of its own: use one host everywhere, in Embed sign-in, in your page's Logto client and in
your MCP servers' metadata. Its audience is your API resource's indicator, the API identifier your page asks Logto for
a token for. Logto signs with ES384 by default, which Embed sign-in reads.

Logto's access tokens carry no name or email, so the agents don't know a person's name until they're told it: add
`name` and `email` to your access tokens as custom token claims in Logto, or have your server tell the agents through
`PUT /users/{id}`.

Your embed code:

```js
// Your API resource’s indicator, as Logto’s API resources show it
const chat = document.querySelector('agent-chat')
chat.getUserToken = () =>
  logtoClient.getAccessToken('https://api.acme.com')
```

Logto doesn't let apps register themselves. Make a client for your agents, in the Logto Console:

1. Go to Applications and choose Create application.
2. Choose Traditional web, name it (Agents, say), and create it.
3. On its page, paste both redirect URIs into Redirect URIs, and save changes.
4. For each MCP server your connectors reach, go to API resources and create one whose API identifier is the server's
   `resource` exactly, as its metadata names it, with the permissions your server asks for.
5. In Roles, give the people who use your agents a role holding those permissions: Logto puts a permission in a token
   only for someone whose role holds it.
6. Copy the App ID and App secret from its page into each connector's Advanced: OAuth client.

Logto gives a refresh token only when a sign-in asks for consent, so a connect at Logto asks for it (`prompt=consent`).
Logto shows its own apps, such as a Traditional web one, no consent screen, so your people still go straight through.

### Google

Google signs people in to its own services, and to servers that sign people in with Google accounts. A connect at
Google asks for access offline, with the person's consent (`access_type=offline`, `prompt=consent`): Google gives a
refresh token only then. So each time a person connects, Google asks them to allow your agents' access, even when
they're signed in to Google already.

Google lets no app register itself. Make a client for your agents in the Google Cloud console: an OAuth client of the
Web application type, with both redirect URIs as its Authorized redirect URIs, and its consent screen set up as Google
asks. Copy its Client ID and Client secret into each connector's Advanced: OAuth client.

### Any OpenID Connect identity provider

Give Embed sign-in its domain, or its issuer's address. Its audience is what your tokens' `aud` holds: often your API's
identifier, or your app's client ID.

Your embed code, here with oidc-client-ts:

```js
// Any OpenID Connect identity provider: its ID or access token,
// here with oidc-client-ts
const chat = document.querySelector('agent-chat')
chat.getUserToken = async () => (await userManager.getUser())?.id_token
```

Many identity providers refuse an app that registers itself until you turn that on, and take no client documents.
Where yours takes neither, make a client for your agents in its admin console:

1. Register a new web application: a confidential client, with a client secret.
2. Add both redirect URIs as its redirect URIs, which some consoles call callback URLs.
3. Allow the authorization code grant with PKCE (S256), refresh tokens with `offline_access`, the scopes your servers
   ask for, and `openid`, `profile` and `email`.
4. Copy its client ID and secret into each connector's Advanced: OAuth client.

## Visitors don't connect accounts

Only a user connects their own accounts. A visitor isn't signed in to your app, so nothing vouches for who they are: an
account connected in their chat would belong to a browser, not to a person your app knows, and no one could find it
again or protect it. So a visitor's turns offer none of the tools on a connector on each user's own login, and their
chat's menu offers no account to connect. An agent anyone may use, which its Share calls "Anyone, including visitors",
gives visitors its other tools.

To let someone connect their own accounts, sign them in to your app: the chat then knows them as a user (How your
people are known, above).

The connections a visitor still has stay theirs until they end: 30 days after the visitor's last visit, or when your
server erases the visitor (`DELETE /visitors/{id}`). Their chat's menu lists them, says when they end, and lets the
visitor disconnect any. Your server lists and removes them with `GET /visitors/{id}/connections` and
`DELETE /visitors/{id}/connections/{connector}`.

## What goes wrong

### In the chat

What a person may see while they connect, why, and what changes it. Each refusal is a problem the API answers too, and
its code links its page.

- **"Open this from your chat"** ([`connect_open_from_chat`](https://hados.io/problems/connect_open_from_chat))
  - Why: a connect goes on only in the window that started it, which holds its binding. This one was opened another
    way, such as a copied link or a new tab.
  - What to change: go back to the chat and choose its card's button. Through the API, where the window started at the
    link's page, it says "This sign-in goes on only in the window it started in. Open the link you were given again,
    and choose Continue there.": open the interrupt's link again, for its person.
- **"This sign-in expired or was already used. Close this window and start again."**
  ([`sign_in_expired`](https://hados.io/problems/sign_in_expired))
  - Why: a sign-in finishes once, within 10 minutes of its start.
  - What to change: start it again from the chat's card, or open the interrupt's link again.
- **"Your account wasn't connected. Close this window and try again."**
  ([`connect_failed`](https://hados.io/problems/connect_failed))
  - Why: the sign-in refused to finish, or couldn't be reached, or its answer named another issuer than the identity
    provider's metadata does.
  - What to change: try again from the chat. If it fails again, check the OAuth client at the provider: both redirect
    URIs, the scopes it allows, and refresh tokens on; and that the `iss` it answers is exactly the `issuer` its
    metadata names.
- **"This account can't be connected right now. Let the app's team know."**
  ([`cant_connect`](https://hados.io/problems/cant_connect))
  - Why: the connector can't sign anyone in until your team changes something, such as an OAuth client it needs, where
    its server's sign-in takes neither a client document nor a registration from it. A visitor who meets a card asking
    them to connect is told the same: only someone signed in connects their own accounts (Visitors don't connect
    accounts, above).
  - What to change: open the connector under Build → Connectors, and give it its own OAuth client in its Settings. For
    a visitor, nothing at the connector: sign them in to your app, and they connect as a user.
- **"This link is no longer open. Go back to the conversation to see where it stands."**
  - Why: the turn no longer waits for this account. It was connected or declined, the turn ended, or 24 hours passed.
  - What to change: go back to the conversation.
- **"This page can't connect accounts: it isn't served over https. Let the site's team know."**
  - Why: the chat's page is served over plain http, where the browser has no Web Crypto for the binding.
  - What to change: serve the page over https. `http://localhost` works while you develop.
- **"The sign-in couldn't start just now. Try again in a moment."**
  - Why: the connect couldn't be asked for: the chat couldn't reach your agents, or the server's identity provider's
    metadata couldn't be read.
  - What to change: try again. If it keeps failing, check your agents are reachable from the page, and that your
    identity provider's metadata answers.
- **"Your browser kept the window from opening. Allow pop-ups for this site, then try again."**
  - Why: the browser blocked the sign-in's window.
  - What to change: allow pop-ups for your site.

### In your setup

- **A server at your identity provider can't act for each person.**
  - Why: its identity provider's document doesn't list the code check MCP requires (PKCE's S256), as Entra ID's and
    Cognito's don't, or it signs no other apps in, as Firebase.
  - What to change: it still checks your people's tokens for the embed. A server that signs people in there can't act
    for each person: when you add it, choose API key.
- **Add a connector says the OAuth client is needed, and doesn't add the connector.**
  - Why: the server's sign-in takes neither a client document nor a registration, as most identity providers don't
    until you turn registration on there.
  - What to change: make a client for your agents at its identity provider (Each provider's setup, above), and enter
    it under Advanced: OAuth client.
- **Signing in to a connector says to "give this connector its own OAuth client, registered with its provider".**
  - Why: the server's sign-in refused a registration, as most identity providers do until you turn that on there.
    Keycloak's Trusted Hosts policy refuses one, Okta wants an API token, and Auth0, Clerk and Supabase keep it behind a
    switch that's off at first.
  - What to change: give the connector its own OAuth client in its Settings, or turn registration on there.
- **Your identity provider's page says the redirect URI isn't allowed.**
  - Why: the OAuth client doesn't list the address the connect comes back to.
  - What to change: add both redirect URIs to the client.
- **People are asked to sign in again right after they connect.**
  - Why: your server refuses the tokens their connections bring, with a 401: most often their audience isn't your
    server, since your identity provider didn't issue them for the `resource` the connect named.
  - What to change: have your identity provider issue tokens for your server's `resource` (as an API's identifier, or
    an API resource's), and have your server read each token's `aud`.
- **A connection says "Signs in again when its access ends" in the chat's menu.**
  - Why: its sign-in brought no refresh token: the client's refresh tokens are off, or your identity provider doesn't
    offer or grant `offline_access`.
  - What to change: allow refresh tokens, and `offline_access`, for the client. The person's next sign-in brings one.
- **A connection says "Sign in again next time" in the chat's menu.**
  - Why: your server refused its token, and it couldn't be renewed: the person removed your agents' access at the
    service, or your identity provider ended its refresh token.
  - What to change: nothing at your end: an agent that needs it asks the person to sign in again.
- **Embed sign-in refuses Entra ID's `common` or `organizations` address.**
  - Why: those name no one issuer.
  - What to change: give your own tenant's, `https://login.microsoftonline.com/YOUR_TENANT_ID/v2.0`.
- **Entra ID's tokens are refused as `wrong issuer`.**
  - Why: version 1 access tokens name `https://sts.windows.net/YOUR_TENANT_ID/` as their issuer.
  - What to change: set `requestedAccessTokenVersion` to `2` in your API's manifest.
- **Entra ID's tokens are refused as `wrong audience`.**
  - Why: version 2 access tokens hold your API's Application (client) ID, not its Application ID URI.
  - What to change: give that ID as the audience.
- **One person chats as two users, in the embed and through the API.**
  - Why: their token's ID isn't the one your servers name them by.
  - What to change: point the person's ID claim, in Embed sign-in, at the claim your servers name them by.
- **Okta's tokens are refused.**
  - Why: your org's own authorization server's access tokens are for Okta's own APIs, and can't be checked.
  - What to change: use a custom authorization server, such as `https://acme.okta.com/oauth2/default`. Custom
    authorization servers come with Okta's API Access Management.
- **A page's token is refused** (`user_token_invalid`).
  - Why: Embed sign-in says why, on the token issuer or signing key that refused it.
  - What to change: paste one into Test a token, in Embed sign-in, to see why. Each reason, and what to change, is in
    [Put an agent on your site](https://hados.io/api/docs/embed).
- **The browser's console says `agent-chat: token-url failed: the server answered 401`.**
  - Why: your path answered an error for someone who isn't signed in.
  - What to change: answer `200` with nothing for them.
- **The browser's console says `agent-chat: token-url must be a path on this site, so it isn't fetched.`**
  - Why: `token-url` names an address on another origin, which the chat never reads: another scheme, host or port.
  - What to change: name a path on your page's own origin, such as `/chat-token`.
- **Resuming a `chat:connect` interrupt answers `not_connected`.**
  - Why: the person hasn't connected yet. For more access (`metadata.chat.more_access`), their account works, but they
    haven't signed in again asking for that access.
  - What to change: open the interrupt's link for them. Once they've connected, the turn goes on by itself: there's
    nothing to resume.
