# Authentication — geonet-console API geonet-console mendukung **3 metode autentikasi** untuk API. --- ## 1. LDAP JWT (untuk pengguna manusia / AI Agent interaktif) Diperoleh dari `POST /api/v1/auth/login` menggunakan kredensial domain LDAP. ``` POST /api/v1/auth/login Content-Type: application/json { "username": "john.doe", "password": "password123" } ``` Response: ```json { "data": { "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...", "token_type": "Bearer", "expires_in": 3600, "auth_type": "ldap_jwt", "user": { "username": "john.doe", "display_name": "John Doe", "is_admin": true } } } ``` Gunakan token pada setiap request: ``` Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9... ``` **TTL:** Default 3600 detik (1 jam). Dikonfigurasi via `API_LDAP_JWT_TTL` di `.env`. **Scope:** JWT dari admin LDAP memiliki akses penuh. JWT dari non-admin hanya akses terbatas. --- ## 2. API Token (untuk service-to-service, server-side automation) Diterbitkan di halaman `/api-clients` oleh admin. Token tidak expire kecuali dihapus manual. ``` Authorization: Bearer geonet_ ``` Setiap API Token memiliki **scope** yang menentukan akses: | Scope | Akses | |-------|-------| | `databases:read` | Baca daftar database | | `databases:write` | Ubah status database | | `ldap:read` | Baca user & group LDAP | | `ldap:write` | Ubah user & group LDAP | | `project-search:read` | Query project search | --- ## 3. Service Token (untuk microservice Bearer token — GeoNetAgent, dll.) Diterbitkan di `/api-clients` → bagian **Service Tokens**. Digunakan oleh microservice seperti GeoNetAgent untuk autentikasi ke collector. ``` Authorization: Bearer Col5FUFl34dVXgyBgTSA23KsYc5QhAh8s224OkR5GjQ ``` > **Catatan:** Service Token divalidasi oleh masing-masing microservice (bukan oleh geonet-console API). geonet-console hanya berfungsi sebagai registry dan management UI. Lihat [`services/service-tokens/README.md`](./services/service-tokens/README.md). --- ## Urutan Prioritas Autentikasi ``` Request masuk ↓ Cek header: Authorization: Bearer ↓ Apakah JWT? (starts with eyJ) → Ya → Validasi JWT LDAP → Tidak → Cek API Token di database → Valid → Lanjut dengan scope token → Tidak valid → 401 Unauthorized ``` --- ## Error Autentikasi | Kode | Kondisi | Solusi | |------|---------|--------| | `401` | Token tidak ada / tidak valid | Login ulang atau cek token | | `401` | JWT expired | Login ulang ke `POST /auth/login` | | `403` | Token valid tapi scope tidak cukup | Minta admin tambah scope | | `429` | Rate limit login (10x/menit) | Tunggu 1 menit |