# Scento auth.md

You are an agent, or an app acting for a Scento customer. This file explains which Scento services need a credential, how to register, how a customer approves your access, and how to use and revoke tokens.

## What needs a credential

- **The public catalogue needs none.** The Scento Perfume API is free and open: the MCP server at https://www.scento.com/mcp and the REST API at https://www.scento.com/api/perfume/v1 (OpenAPI: https://www.scento.com/openapi.json; documentation: https://www.scento.com/developers).
- **A customer's own orders need the customer's approval.** The account MCP server at `https://www.scento.com/mcp/account` lists the signed-in customer's orders and shows one order (order number, date, status, items and quantities, total, tracking link). It is read-only: nothing here can place, change, cancel or pause an order or anything else on the account, and it never returns payment details, passwords or addresses.

## Step 1: Discover

- Authorization server metadata (RFC 8414): `GET https://www.scento.com/.well-known/oauth-authorization-server`
- Protected resource metadata (RFC 9728): `GET https://www.scento.com/.well-known/oauth-protected-resource/mcp/account`
- A call to `https://www.scento.com/mcp/account` without a token answers `401` with `WWW-Authenticate: Bearer resource_metadata="https://www.scento.com/.well-known/oauth-protected-resource/mcp/account", scope="orders:read"`.
- Signing keys (JWKS): `GET https://www.scento.com/.well-known/jwks.json`

## Step 2: Register (pick one method)

1. **Client ID Metadata Document** (preferred for MCP clients): use an https URL that serves your client metadata JSON as your `client_id`. The document must contain `client_id` (its own URL), `client_name` and `redirect_uris`, and use `token_endpoint_auth_method: "none"`. Nothing to register; the customer sees your document's host on the approval page.
2. **Agent registration** (anonymous, credential type `client_secret`):

   POST /oauth/agent/register

   ```json
   {"type": "anonymous", "client_name": "Example Agent", "redirect_uris": ["http://127.0.0.1/callback"]}
   ```

   The answer carries `registration_id`, `client_id`, `client_secret`, `pre_claim_scopes` (`catalog:read`) and `post_claim_scopes` (`orders:read`, once a customer approves). `redirect_uris` is optional; without it you can only use the catalogue scope. Keep the secret private; send it only to the token and revocation endpoints.
3. **Dynamic client registration** (RFC 7591):

   POST /oauth/register

   with `client_name`, `redirect_uris` (https, or http on 127.0.0.1, [::1] or localhost) and `token_endpoint_auth_method` (`none`, `client_secret_basic` or `client_secret_post`). Every registration answers with a `client_secret`, a public one too (it may ignore it); present it at the token endpoint for a catalogue token.

Redirect URIs are matched exactly. For a loopback redirect only the port may differ from the registered one.

## Step 3: The customer approves (authorization code with PKCE)

Send the customer's browser to:

```
https://www.scento.com/oauth/authorize?response_type=code&client_id=<client_id>&redirect_uri=<redirect_uri>&scope=orders:read&state=<random>&code_challenge=<S256 challenge>&code_challenge_method=S256&resource=https%3A%2F%2Fwww.scento.com%2Fmcp%2Faccount
```

- PKCE with `S256` is required; `plain` is refused.
- `resource` (RFC 8707) is required and must be `https://www.scento.com/mcp/account`.
- The customer signs in to their Scento account if needed (https://www.scento.com/sign-in), sees your name, the host you send them back to and what you may read, and chooses Allow or Deny. There is no automatic approval.
- The redirect carries `code`, your `state` and `iss=https://www.scento.com` (RFC 9207); check `iss`.

Exchange the code within 60 seconds (it works once):

```
POST /oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=<code>&redirect_uri=<redirect_uri>&code_verifier=<verifier>&client_id=<client_id>&resource=https%3A%2F%2Fwww.scento.com%2Fmcp%2Faccount
```

Confidential clients authenticate with HTTP Basic (`client_secret_basic`) or `client_secret` in the body.

## Step 4: Catalogue token (optional)

```
POST /oauth/token
Authorization: Basic base64(client_id:client_secret)

grant_type=client_credentials&scope=catalog:read
```

The token always carries `catalog:read` only. A Client ID Metadata Document that lists `client_credentials` sends its `client_id` instead of a secret. The catalogue endpoints are public, so this token is optional today.

## Step 5: Use the token

Send `Authorization: Bearer <access_token>` to `https://www.scento.com/mcp/account` with MCP JSON-RPC over HTTP POST (`initialize`, `tools/list`, `tools/call`). Tools: `list_my_orders` and `get_order` (by the order number the customer sees). Access tokens are ES256 JWTs (`typ: at+jwt`) for audience `https://www.scento.com/mcp/account` and last 60 minutes.

## Refresh

`grant_type=refresh_token&refresh_token=<token>&client_id=<client_id>`. Every refresh returns a NEW refresh token; the old one stops working. Using an old refresh token again ends the whole grant, so store the newest one only. Access ends after 30 days without use, 90 days after the customer approved (ask them again then), and when the customer changes their password.

## Revocation

```
POST /oauth/revoke

token=<access or refresh token>&client_id=<client_id>
```

(RFC 7009, same client authentication as the token endpoint.) Revoking a customer access or refresh token ends the whole grant it belongs to. Catalogue (`client_credentials`) tokens are not tracked and simply expire after 60 minutes. The answer is `200` even for an unknown token.

## Errors

| Answer | Meaning |
|---|---|
| `401` `invalid_token` | Token missing, expired, revoked, or for another audience: refresh it or ask the customer again |
| `403` `insufficient_scope` | The token lacks `orders:read` |
| `400` `invalid_grant` | Code or refresh token expired, used twice or not yours |
| `400` `invalid_target` | `resource` missing or not `https://www.scento.com/mcp/account` |
| `401` `invalid_client` | Unknown client or wrong secret |
| `429` | Too many requests: wait for `Retry-After` seconds |
| `503` `temporarily_unavailable` | Try again shortly |

## Contact

https://www.scento.com/contact
