# Connecting a person's Begad account

The public server needs nothing. The **account server** (`https://begad.ae/api/agent/mcp/account`) shows the person's own orders, cart and wishlist, and `create_cart` there puts items straight into their Begad cart. It uses OAuth 2.1 with PKCE, as the MCP specification describes, so Claude and ChatGPT handle it on their own: add the account server URL and the person is sent to Begad to sign in and approve.

## What the person sees

They sign in on begad.ae (password, Google, Apple), then a page names the assistant and what it may do, with **Allow** and **Cancel**. It also says the assistant can never place orders, pay, or see addresses, phone numbers or cards. They can disconnect it any time under **My Account > Connected assistants**; that stops it at once.

## Endpoints

| | |
|---|---|
| Resource metadata | `https://begad.ae/.well-known/oauth-protected-resource/api/agent/mcp/account` |
| Server metadata | `https://begad.ae/.well-known/oauth-authorization-server` |
| Register a client (RFC 7591) | `POST https://begad.ae/api/agent/oauth/register` |
| Authorize | `https://begad.ae/api/agent/oauth/authorize` |
| Token | `POST https://begad.ae/api/agent/oauth/token` |
| Revoke (RFC 7009) | `POST https://begad.ae/api/agent/oauth/revoke` |

- Public clients only: PKCE with S256 is required, no client secret.
- Redirect URIs must be `https`, or `http` on `127.0.0.1` / `localhost` (any port) for CLIs and desktop apps.
- Access tokens last 1 hour; refresh tokens 90 days. Send `Authorization: Bearer <token>`.
- A request without a valid token gets `401` with `WWW-Authenticate: Bearer resource_metadata="..."`.

## Scopes

| Scope | Allows |
|---|---|
| `shopping` | Search and build cart links |
| `cart` | Read the person's cart and add to it |
| `orders` | Read their orders and delivery status |
| `wishlist` | Read their wishlist |

Leave `scope` out to ask for all four. The person approves them together.

## Your own client

```bash
# 1. Register once
curl -s -X POST https://begad.ae/api/agent/oauth/register -H 'Content-Type: application/json' \
  -d '{"client_name":"My shopping agent","redirect_uris":["http://127.0.0.1:8765/callback"]}'
# 2. Send the person to
#    https://begad.ae/api/agent/oauth/authorize?response_type=code&client_id=...&redirect_uri=...&code_challenge=...&code_challenge_method=S256&state=...
# 3. Exchange the code
curl -s -X POST https://begad.ae/api/agent/oauth/token \
  -d grant_type=authorization_code -d client_id=... -d code=... -d code_verifier=... -d redirect_uri=...
```
