# auth.md — Pictify agent registration

Pictify supports one agent-registration flow today: **service_auth** via
OAuth 2.0 Device Authorization Grant ([RFC 8628](https://www.rfc-editor.org/rfc/rfc8628)).
A human with an existing Pictify account approves your agent from a real
browser; no separate identity-provider trust relationship is required.

Full machine-readable metadata: [`https://api.pictify.io/.well-known/oauth-authorization-server`](https://api.pictify.io/.well-known/oauth-authorization-server)
(RFC 8414, extended with an `agent_auth` block).

## 1. Discover

```
GET https://api.pictify.io/.well-known/oauth-authorization-server
```

## 2. Register (once, per agent/client — RFC 7591)

```
POST https://api.pictify.io/oauth/register
Content-Type: application/json

{ "redirect_uris": ["https://your-agent.example/callback"], "client_name": "Your Agent" }
```

Returns `client_id` (and `client_secret`, unused for this flow).

## 3. Get a device code

```
POST https://api.pictify.io/oauth/device_authorization
Content-Type: application/json

{ "client_id": "<client_id>" }
```

Returns `device_code` (keep this, poll with it), `user_code` and
`verification_uri` (show these to the human), `expires_in`, `interval`.

## 4. Have the human approve

Direct the human to `verification_uri_complete` (or `verification_uri` +
`user_code`), e.g. `https://pictify.io/device?user_code=XXXX-XXXX`. They log in
if needed and approve or deny your agent's request.

## 5. Exchange (poll)

```
POST https://api.pictify.io/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=<device_code>&client_id=<client_id>
```

Poll no faster than `interval` seconds. Responses: `authorization_pending`
(keep polling), `slow_down` (back off), `access_denied` (human declined,
stop), or a real `access_token` once approved. `device_code` is one-time
use — you get exactly one token per approval.

## 6. Use

```
Authorization: Bearer <access_token>
```

against Pictify's API endpoints (see [https://docs.pictify.io](https://docs.pictify.io) for the full reference).

## 7. Revoke

```
POST https://api.pictify.io/oauth/revoke
Content-Type: application/json

{ "token": "<access_token>" }
```
