# auth.md

HemenYedekParça API'si yapay zekâ ajanlarına ve otonom istemcilere açıktır.
Bu belge, bir ajanın kimlik alma ve yetkilendirme sürecini tarif eder.

## Kimler için

- Kullanıcı adına hareket eden LLM ajanları (ChatGPT, Claude, Gemini, Perplexity vb.)
- MCP ve A2A istemcileri
- Katalog/ilan verisini okuyan otomasyonlar

Okuma uçları (`catalog.read`, `search.read`) anonim olarak da çağrılabilir.
Yazma uçları (`requests.write`) erişim jetonu gerektirir.

## Dinamik istemci kaydı

Önceden anlaşma gerekmez. RFC 7591 ile kendinizi kaydedin:

```http
POST https://hemenyedekparca.com/oauth/register
Content-Type: application/json

{"client_name":"Ornek Ajan","redirect_uris":["https://ornek.dev/callback"],"grant_types":["authorization_code","client_credentials"]}
```

Yanıt `client_id` içerir. Public istemcilerde `client_secret` verilmez; PKCE (S256) zorunludur.

## Metadata uçları

| Belge | URL |
| --- | --- |
| Authorization Server Metadata | https://hemenyedekparca.com/.well-known/oauth-authorization-server |
| OpenID Configuration | https://hemenyedekparca.com/.well-known/openid-configuration |
| Protected Resource Metadata | https://hemenyedekparca.com/.well-known/oauth-protected-resource |
| JWKS | https://hemenyedekparca.com/oauth/jwks.json |
| OpenAPI 3.1 | https://hemenyedekparca.com/openapi.json |
| API kataloğu | https://hemenyedekparca.com/.well-known/api-catalog |

## Kimlik bilgisinin kullanımı

Erişim jetonu HTTP başlığında taşınır:

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

Jeton geçersizse uç `401` döner ve `WWW-Authenticate` başlığında
`resource_metadata="https://hemenyedekparca.com/.well-known/oauth-protected-resource"` bildirilir.

## Kapsamlar

| Kapsam | Açıklama |
| --- | --- |
| `catalog.read` | Katalog ve ilan verilerini okuma |
| `search.read` | Arama yapma |
| `requests.write` | Parça talebi oluşturma |

## Kendi kendine yeten kayıt akışı

Aşağıdaki üç adım, başka hiçbir belgeye bakmadan istemci kaydı ve jeton
alımı için yeterlidir.

**1) İstemci kaydı (RFC 7591, kimlik doğrulama gerekmez)**

```http
POST https://hemenyedekparca.com/oauth/register
Content-Type: application/json

{"client_name":"Örnek Agent","redirect_uris":["https://ornek-agent.example/cb"],
 "grant_types":["authorization_code","client_credentials"],
 "token_endpoint_auth_method":"none","scope":"catalog.read search.read requests.write"}
```
Yanıt: `client_id` (ve istenirse `client_secret`).

**2) Jeton alımı (anonim makine erişimi)**

```http
POST https://hemenyedekparca.com/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&client_id=CLIENT_ID&scope=catalog.read+search.read
```
Yanıt: `access_token`, `token_type=Bearer`, `expires_in=3600`.

**3) Korunan kaynağa erişim**

```http
POST https://hemenyedekparca.com/api/v1/requests
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json

{"title":"Aranan parça","contact":"+90...","city":"istanbul"}
```
Yetkisiz istek `401` ve `WWW-Authenticate: Bearer resource_metadata="https://hemenyedekparca.com/.well-known/oauth-protected-resource"` döner.

Kullanıcı adına erişim gerekiyorsa `authorization_code` + PKCE (`S256`) akışı
`https://hemenyedekparca.com/oauth/authorize` üzerinden kullanılır.

## Makine tarafından okunabilir yapılandırma

```yaml
agent_auth:
  skill: https://hemenyedekparca.com/auth.md
  skills:
    - https://hemenyedekparca.com/.well-known/agent-skills/index.json
  claim_uri: https://hemenyedekparca.com/auth.md
  register_uri: https://hemenyedekparca.com/oauth/register
  identity_types_supported: [anonymous]
  anonymous:
    credential_types_supported: [oauth2_client_credentials]
  methods:
    - type: oauth2_dynamic_registration
      registration_endpoint: https://hemenyedekparca.com/oauth/register
      authorization_endpoint: https://hemenyedekparca.com/oauth/authorize
      token_endpoint: https://hemenyedekparca.com/oauth/token
      grant_types: [authorization_code, client_credentials]
      code_challenge_methods: [S256]
      scopes: [catalog.read, search.read, requests.write]
```

## İletişim

agents@hemenyedekparca.com
