Skip to main content
Tool Gateway is in beta.
An OAuth connect link lets a user sign in to a provider and connect their account. A verify page checks that the person signed in to your app is the intended user before sending them to the provider. If someone else opens a forwarded or leaked link, they cannot connect an account in that user’s place. Agent Auth stores the provider accounts that your users connect for Tool Gateway calls, such as their Google or GitHub accounts.

Who needs a verify page

Only OAuth connect links for the following users can use a verify page: When one of these users calls an OAuth server they have not connected, the call returns a connect link. See When the caller is a user. Links that prompt for an API key skip the verify page. Users who have a LangSmith login sign in to LangSmith instead of visiting your verify page. An eligible OAuth connect link opens a LangSmith page that shows the provider and the intended user. Opening the page does not use the link, so chat previews do not consume it. Only the first browser to click Continue can finish the sign-in. What happens next depends on whether the workspace has a verify page:
  • Without a verify page: The browser goes straight to the provider. If someone else uses the link and signs in, LangSmith links their provider account to the intended user. Tool calls for that user then use the wrong account.
  • With a verify page: The browser goes to your verify page. Your app identifies the signed-in user and asks LangSmith to confirm that they are the intended user. Only after confirmation does the browser continue to the provider.
The authorization session behind a connect link expires 10 minutes after LangSmith creates it.

Set the verify page

Each workspace has one verify page URL. Viewing the setting in the UI requires the workspaces:read and workspaces:credentials:read-metadata permissions. Changing or removing the URL also requires the workspaces:credentials:manage permission. The URL must be an absolute https URL of up to 2048 bytes. It cannot contain user info, a fragment, or a session_id query parameter. LangSmith preserves any other query parameters when it redirects to your page.
To configure the verify page in LangSmith:
  1. Go to Settings > Workspace, and select Agent Connections under Integrations.
  2. Open the Connect Links tab.
  3. In the Verify Page row, click Set up.
  4. In the Set Up Verify Page dialog, enter the Verify Page URL, then click Save verify page.
The row then shows the URL. To change it, click Edit. To remove it, click Edit, click Remove, and confirm.

Build the verify page

When the user clicks Continue, LangSmith sends a 303 redirect to your verify page with session_id=<uuid> in the query string. In your verify page handler:
  1. Read session_id and reject it if it is not a UUID.
  2. Identify the user signed in to your app. If no one is signed in, prompt the user to sign in, then return them to the verify page with the original query string.
  3. From your backend, confirm the user with LangSmith.
  4. Act on the response: redirect the browser to the LangSmith resume URL or show an error.
If the session expires before your page confirms it, the confirmation request returns 409, and the user needs a new link.

Confirm the signed-in user

Send POST /v1/agent-auth/oauth-authorization-sessions/<session-id>/confirmation with no body and these headers:
  • X-Api-Key: A service key with the workspaces:credentials:use or agent-auth-credentials:use permission.
  • X-Tenant-Id: The workspace ID.
  • The signed-in user: X-LangSmith-Identity or X-Agent-Auth-Principal-Authorization, as the following examples show.
Send the confirmation request from your backend. It carries your service key, which must stay on servers you control.
To identify the user from your backend, send X-LangSmith-Identity with the same value your backend sends on Tool Gateway calls for that user, or the user’s principal ID:
For a user of your linked identity provider, send the user’s access token in X-Agent-Auth-Principal-Authorization instead:
This header name differs from the Authorization header that carries the same token on Tool Gateway calls.

Act on the response

The confirmation status determines what your page does next: The returned url is a single-use LangSmith resume URL, not the provider sign-in URL. It starts provider sign-in only in the browser that clicked Continue. Error responses use problem details JSON. The detail field describes the error.

Example

Add the verify route to your app server using Starlette for Python or Hono for TypeScript. Both examples read these environment variables:
  • LANGSMITH_ENDPOINT: The LangSmith API URL for your region, such as https://api.smith.langchain.com. See Base URL.
  • LANGSMITH_API_KEY: The service key for the confirmation request.
  • LANGSMITH_WORKSPACE_ID: The workspace ID.
The example identifies the user as myapp:<user-id>. Replace myapp with the prefix your backend sends on Tool Gateway calls. For users of your identity provider, send X-Agent-Auth-Principal-Authorization with the user’s access token instead of X-LangSmith-Identity.
Before using this route in your app, replace get_signed_in_user (getSignedInUser in TypeScript) with a lookup that verifies your app’s authenticated session. The demo reads an unverified cookie. Do not use that cookie as proof of identity.

Handle a user mismatch

If the signed-in user does not match the intended user, or Agent Auth does not recognize the identity you sent, the confirmation request returns 403. The detail is the user is not the session's owner. LangSmith stops the flow before provider sign-in and marks the session as failed with error_code set to user_mismatch. Tell the user that the link belongs to someone else. Do not offer to retry the failed session. Get a new connect link for the intended user the same way your app got the first one. To check for a mismatch from your backend, send GET /v1/agent-auth/oauth-authorization-sessions/<session-id> using the session_id from the verify page. Reading a user-owned session requires workspaces:read or workspaces:credentials:read-metadata. If you send an identity provider token, it must match the session owner. Check whether error_code is user_mismatch.

Troubleshoot

The confirmation request returns these errors: LangSmith also shows errors on its own pages:
  • The link does not work (404): Check that the user opened the full link. If it still does not work, ask for a new link.
  • The link expired or was already used (410): The user needs a new link.
  • The link was continued in another browser (409): Finish in the browser that clicked Continue, or ask for a new link.

See also