> For the complete documentation index, see [llms.txt](https://developer.konukcrm.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.konukcrm.com/rehberler/kimlik-dogrulama.md).

# Kimlik Doğrulama

KonukCRM API'si **Bearer JWT** kullanır. Her istekte:

```http
Authorization: Bearer <accessToken>
```

Token, arkasındaki kullanıcının **tenant'ına ve rol izinlerine** bağlıdır. Ayrı bir tenant başlığı göndermeniz gerekmez.

## Token yaşam döngüsü

```
login ──► accessToken (kısa ömürlü) + refreshToken (uzun ömürlü)
         │
         ├─ 401 alındı ──► POST /auth/refresh ──► yeni çift
         │
         └─ oturum bitti ──► POST /auth/logout (refreshToken iptal)
```

| Token          | Ömür          | Nerede saklanır                            |
| -------------- | ------------- | ------------------------------------------ |
| `accessToken`  | {{15 dakika}} | Bellek. `localStorage` **kullanmayın**.    |
| `refreshToken` | {{30 gün}}    | Sunucu tarafı gizli depo / HttpOnly cookie |

## Giriş

`POST /auth/login`

```json
{ "email": "entegrasyon@oteliniz.com", "password": "********" }
```

Hız limiti uygulanır (`auth` politikası). Ardışık başarısız denemeler `429` döndürür.

## Yenileme

`POST /auth/refresh`

```json
{ "refreshToken": "9f2c..." }
```

Yenileme token'ları **tek kullanımlıktır**: her yenilemede yeni bir çift alırsınız ve eskisi geçersizleşir. Aynı refresh token'ı iki kez kullanmak tüm oturumu iptal eder.

### Önerilen istemci deseni

```typescript
// tek uçuşta yenileme: eşzamanlı 401'ler tek bir refresh çağrısını paylaşır
let inFlight: Promise<Tokens> | null = null;

async function withAuth(request: () => Promise<Response>) {
  let res = await request();
  if (res.status !== 401) return res;

  inFlight ??= refreshTokens().finally(() => { inFlight = null; });
  await inFlight;
  return request(); // bir kez tekrar dene, döngüye girme
}
```

## Çıkış

`POST /auth/logout` — gövdede `refreshToken`. Erişim token'ı doğal süresi dolana kadar geçerli kalır; kritik durumlarda kullanıcı oturumlarını sunucudan iptal edin.

## Diğer hesap uçları

| Uç                               | Amaç                                |
| -------------------------------- | ----------------------------------- |
| `POST /auth/register`            | Yeni tenant/kullanıcı kaydı         |
| `POST /auth/confirm-email`       | E-posta doğrulama                   |
| `POST /auth/resend-confirmation` | Doğrulama e-postasını tekrar gönder |
| `POST /auth/forgot-password`     | Sıfırlama bağlantısı iste           |
| `POST /auth/reset-password`      | Yeni parola belirle                 |

## Güvenlik kuralları

1. Kimlik bilgilerini **istemci tarafı koda gömmeyin**. Tarayıcıdan doğrudan API çağrısı yapmayın; kendi sunucunuz üzerinden proxy'leyin.
2. Entegrasyonlar için **ayrı bir servis kullanıcısı** oluşturun ve yalnızca gereken izinleri verin.
3. Sızdığından şüphelendiğiniz her kimlik bilgisini derhal döndürün (rotate).
4. Tüm trafik TLS üzerindedir; HTTP çağrıları reddedilir.

## Sık karşılaşılan hatalar

| Belirti                         | Sebep                                        | Çözüm                                       |
| ------------------------------- | -------------------------------------------- | ------------------------------------------- |
| Sürekli `401`                   | Süresi dolmuş `accessToken`                  | Yenileme akışını uygulayın                  |
| `401` sonrası yenileme de `401` | Refresh token yeniden kullanılmış veya iptal | Yeniden giriş yapın                         |
| `403`, token geçerli            | Kullanıcının rolünde ilgili izin yok         | {{Ayarlar → Roller}} üzerinden izin ekleyin |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developer.konukcrm.com/rehberler/kimlik-dogrulama.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
