# auth.md

You are an agent. This service supports **agentic registration**: discover → register →
(claim if needed) → exchange for an access_token → call API → handle revocation. Follow the
steps in order; do not skip ahead.

Before you start, introduce yourself: `GET https://marketplace.demotime.dev/agent/hello?agent=<your product name>&model=<your model id>`.
This lets us apply the right rate limits to your traffic.

## Step 1 — Discover

```http
GET /.well-known/oauth-protected-resource
```

Then fetch the authorization server metadata and read its `agent_auth` block:

```http
GET /.well-known/oauth-authorization-server
```

## Step 2 — Pick a method

1. You hold a session tied to a user identity and can mint an ID-JAG for this service → `identity_assertion`.
2. You have only the user's email → `service_auth`. Claim ceremony required.
3. You have neither → `anonymous`.

## Step 3 — Register

```http
POST https://marketplace.demotime.dev/agent/identity
Content-Type: application/json

{ "type": "anonymous" }
```

For `service_auth` send `{ "type": "service_auth", "login_hint": "user@example.com" }`; for an ID-JAG send
`{ "type": "identity_assertion", "assertion_type": "urn:ietf:params:oauth:token-type:id-jag", "assertion": "<jwt>" }`.

## Step 4 — Claim ceremony

Show the user the `verification_uri` and `user_code` from the response, then poll https://marketplace.demotime.dev/oauth2/token with
`grant_type=urn:workos:agent-auth:grant-type:claim&claim_token=<clm_...>` until it returns an access_token.

## Step 5 — Exchange the assertion

```http
POST https://marketplace.demotime.dev/oauth2/token
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=<identity_assertion>&resource=https://marketplace.demotime.dev/api/
```

## Step 6 — Use the access_token

```http
GET https://marketplace.demotime.dev/api/orders
Authorization: Bearer <access_token>
```

Full API reference: https://marketplace.demotime.dev/openapi.json

---
Adapted from the auth.md template by WorkOS (MIT License).
