# auth.md

American Police Training supports agentic registration. Agents register against this service, obtain a service-signed identity assertion, and exchange it for a Bearer access token.

- Resource server: `https://americanpolicetraining.com/`
- Authorization server: `https://americanpolicetraining.com/`

## 1. Discover

1. On API `401`, read `WWW-Authenticate: Bearer resource_metadata="…"`, or fall back to `https://americanpolicetraining.com/.well-known/oauth-protected-resource`.
2. Fetch Protected Resource Metadata for `resource`, `authorization_servers`, `scopes_supported`, and `bearer_methods_supported`.
3. Fetch Authorization Server metadata at `https://americanpolicetraining.com/.well-known/oauth-authorization-server` for `issuer`, `token_endpoint`, `revocation_endpoint`, `grant_types_supported`, and the `agent_auth` block (`skill`, `identity_endpoint`, `claim_endpoint`, `events_endpoint`, identity types).

## 2. Pick a method

| You have | Use |
| --- | --- |
| ID-JAG bound to this audience | `identity_assertion` |
| User email only | `service_auth` |
| Neither | `anonymous` |

Supported scopes: `profile.read`, `profile.write`. Pre-claim anonymous scope: `profile.read`. Post-claim: `profile.read`, `profile.write`.

## 3. Register

`POST https://americanpolicetraining.com/agent/identity` with `Content-Type: application/json`.

### identity_assertion

```http
POST /agent/identity HTTP/1.1
Content-Type: application/json
```

```json
{
  "type": "identity_assertion",
  "assertion_type": "urn:ietf:params:oauth:token-type:id-jag",
  "assertion": "<ID-JAG JWT>"
}
```

### service_auth

```json
{
  "type": "service_auth",
  "login_hint": "user@example.com"
}
```

Returns `claim_token` and a `claim` block (`user_code`, `verification_uri`). No assertion until the user completes the claim ceremony.

### anonymous

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

Returns a pre-claim `identity_assertion` plus `claim_token`.

## 4. Claim ceremony

For `service_auth`, the `claim` block is in the registration response. For `anonymous`, `POST https://americanpolicetraining.com/agent/identity/claim` with `{ "claim_token", "email" }`.

Surface `verification_uri` and `user_code` to the user. The user signs in at this service and completes `https://americanpolicetraining.com/agent/claim`. Poll `https://americanpolicetraining.com/oauth2/token` with `grant_type=urn:workos:agent-auth:grant-type:claim` until complete.

## 5. Exchange the assertion

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

grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=<identity_assertion>&resource=https://americanpolicetraining.com/
```

Response: `access_token` (prefix `agt_`), `token_type=Bearer`, `expires_in`, `scope`. No refresh token — re-exchange the assertion.

## 6. Use the access_token

`Authorization: Bearer agt_…` on API requests. When the access token expires, re-exchange the `identity_assertion`. If the assertion is revoked or expired, re-register.

## 7. Revocation

- Credential: `POST https://americanpolicetraining.com/oauth2/revoke` with the access token (RFC 7009).
- Registration: providers POST Security Event Tokens to `https://americanpolicetraining.com/agent/event/notify`.

## Contact

Integration issues: support via the American Police Training help center on this host.
