# auth.md

Bu belge, `dogumharitasi.pro` üzerindeki agent uçlarına nasıl kimlik doğrulanacağını anlatır.
Hedef kitle: otonom AI agent'ları ve MCP istemcileri.

## Kimlik gerekiyor mu?

Hayır — zorunlu değil. `POST /mcp` **anonim** olarak da çalışır (IP başına saatte 20 çağrı).
Daha yüksek güvenilirlik ve limit takibi isteyen agent'lar aşağıdaki akışla anonim bir istemci
kimliği alabilir. E-posta veya insan onayı gerekmez.

## 1. Kayıt (anonim)

```http
POST /agent/register HTTP/1.1
Host: dogumharitasi.pro
Content-Type: application/json

{"name": "ornek-agent"}
```

Yanıt:

```json
{
  "client_id": "…32 hex…",
  "client_secret": "…64 hex…",
  "token_endpoint": "https://dogumharitasi.pro/oauth/token",
  "grant_types": ["client_credentials"],
  "scope": "chart:read"
}
```

`client_secret` yalnızca bir kez döndürülür; saklayın. Kayıt limiti: IP başına saatte 5.

## 2. Erişim anahtarı (client_credentials)

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

grant_type=client_credentials&client_id=…&client_secret=…
```

Yanıt: `{"access_token": "…", "token_type": "Bearer", "expires_in": 3600, "scope": "chart:read"}`

## 3. Kullanım

```http
POST /mcp HTTP/1.1
Authorization: Bearer <access_token>
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call",
 "params":{"name":"natal_chart","arguments":{
   "name":"Ornek","birthdate":"1990-06-01","birthtime":"14:20",
   "birthplace":"Ankara","country":"TR"}}}
```

## Hatalar

- `401` → `WWW-Authenticate: Bearer resource_metadata="https://dogumharitasi.pro/.well-known/oauth-protected-resource"`
- `429` → limit aşıldı (anonim MCP: 20/saat, kayıt: 5/saat).

## agent_auth metadata

Bu bloğun aynısı `/.well-known/oauth-protected-resource` içinde `agent_auth` alanı olarak da yayınlanır.

```json
{
  "agent_auth": {
    "skill": "https://dogumharitasi.pro/.well-known/agent-skills/natal-chart/SKILL.md",
    "register_uri": "https://dogumharitasi.pro/agent/register",
    "claim_uri": "https://dogumharitasi.pro/agent/register",
    "identity_types_supported": ["anonymous"],
    "credential_types_supported": ["client_credentials"],
    "anonymous": {
      "credential_types_supported": ["client_credentials"],
      "claim_uri": "https://dogumharitasi.pro/agent/register"
    },
    "methods": [
      {
        "type": "anonymous",
        "register_uri": "https://dogumharitasi.pro/agent/register",
        "claim_uri": "https://dogumharitasi.pro/agent/register",
        "credential_types_supported": ["client_credentials"],
        "token_uri": "https://dogumharitasi.pro/oauth/token",
        "scopes_supported": ["chart:read"]
      }
    ]
  }
}
```

### Registration (English summary)

Agents register anonymously with `POST /agent/register` (no email required), then obtain a
bearer token with `POST /oauth/token` using the `client_credentials` grant and scope
`chart:read`. Credentials are used as `Authorization: Bearer <access_token>` on `/mcp`.

## İlgili belgeler

- Korunan kaynak meta verisi: `/.well-known/oauth-protected-resource`
- Yetkilendirme sunucusu meta verisi: `/.well-known/oauth-authorization-server`
- Beceri dokümanı: `/.well-known/agent-skills/natal-chart/SKILL.md`
- OpenAPI: `/openapi.json`
