GAuth-Central - Centralized Authentication Service
Modern, ölçeklenebilir ve güvenli bir kimlik doğrulama servisi. PostgreSQL ve Redis ile desteklenir.
🚀 Özellikler
- ✅ JWT tabanlı kimlik doğrulama
- ✅ OAuth2 entegrasyonu (Google, GitHub)
- ✅ Email doğrulama
- ✅ Redis ile session yönetimi ve caching
- ✅ PostgreSQL ile veri saklama
- ✅ Rate limiting
- ✅ Token blacklist (logout)
- ✅ CORS desteği
- ✅ Swagger/OpenAPI dokümantasyonu
- ✅ Docker & Docker Compose desteği
📋 Gereksinimler
- Go 1.25+
- PostgreSQL 17+
- Redis 7+
- Docker & Docker Compose (opsiyonel)
🛠️ Kurulum
1. Repository'yi klonlayın
git clone <repository-url>
cd AuthCentral
2. Environment dosyasını ayarlayın
cp .env.example .env
# .env dosyasını kendi ayarlarınıza göre düzenleyin
3. Bağımlılıkları yükleyin
go mod download
4a. Standalone Mode (Mevcut PostgreSQL & Redis kullanarak)
Eğer zaten çalışan PostgreSQL ve Redis sunucularınız varsa:
# .env dosyasında DB_URL ve REDIS_URL'i ayarlayın
# Örnek:
# DB_URL="host=10.80.80.70 user=cloud password=xxx dbname=go_gauth port=5432 sslmode=disable"
# REDIS_URL=redis://default:xxx@10.80.80.70:6379/0
# Uygulamayı başlat
./start.sh
# veya manuel
go run main.go
4b. Docker ile çalıştırma
# Tüm servisleri başlat (PostgreSQL, Redis, App)
docker-compose up -d
# Logları takip et
docker-compose logs -f app
4b. Docker ile çalıştırma
Docker ile tüm servisleri (PostgreSQL, Redis, App) birlikte başlatmak için:
# Tüm servisleri başlat (PostgreSQL, Redis, App)
docker-compose up -d
# Logları takip et
docker-compose logs -f app
5. Bağlantı Testi
# API sağlık kontrolü
curl http://localhost:8080/
# Swagger dokümantasyonu
open http://localhost:8080/docs/index.html
🔧 Yapılandırma
Environment Variables
| Değişken | Açıklama | Örnek |
|---|---|---|
PORT |
Uygulama portu | 8080 |
DB_URL |
PostgreSQL bağlantı string'i | host=localhost user=postgres password=pass dbname=gauth port=5432 sslmode=disable |
REDIS_URL |
Redis bağlantı URL'i | redis://default:password@localhost:6379/0 |
JWT_SECRET |
JWT için gizli anahtar | your_secret_key |
GOOGLE_CLIENT_ID |
Google OAuth Client ID | - |
GOOGLE_CLIENT_SECRET |
Google OAuth Client Secret | - |
GITHUB_CLIENT_ID |
GitHub OAuth Client ID | - |
GITHUB_CLIENT_SECRET |
GitHub OAuth Client Secret | - |
CLIENT_CALLBACK_URL |
OAuth callback URL | http://localhost:8080/v1/auth |
📚 API Dokümantasyonu
Swagger UI: http://localhost:8080/docs/index.html
Temel Endpoint'ler
Authentication
POST /v1/auth/register- Yeni kullanıcı kaydıPOST /v1/auth/login- Kullanıcı girişiGET /v1/auth/verify-email- Email doğrulamaPOST /v1/auth/refresh- Token yenilemeGET /v1/auth/:provider- OAuth ile giriş (google, github)GET /v1/auth/:provider/callback- OAuth callback
Protected Routes (Authorization gerekli)
GET /v1/auth/me- Kullanıcı bilgilerini getirGET /v1/auth/validate- Token doğrulama
🗄️ Veritabanı Yapısı
PostgreSQL Tables
users- Kullanıcı bilgilerisocial_accounts- OAuth hesap bağlantılarıroles- Kullanıcı rolleripermissions- İzinler
Redis Cache Keys
user:{id}- Kullanıcı cachesession:{token}- Session yönetimiblacklist:{token}- Token blacklistratelimit:{key}- Rate limitingemail_verify:{email}- Email doğrulama token'larıpassword_reset:{email}- Şifre sıfırlama token'ları
🔒 Güvenlik
- Şifreler bcrypt ile hashlenmiş olarak saklanır
- JWT token'lar Authorization header'da Bearer token olarak gönderilir
- CORS politikaları yapılandırılmıştır
- Rate limiting Redis ile yönetilir
- Logout sonrası token'lar blacklist'e eklenir
🐳 Docker Compose
Uygulama 3 servis ile çalışır:
- PostgreSQL - Ana veritabanı (Port: 5432)
- Redis - Cache ve session store (Port: 6379)
- App - Go backend (Port: 8080)
# Servisleri başlat
docker-compose up -d
# Servisleri durdur
docker-compose down
# Volume'ları da sil
docker-compose down -v
🧪 Development
Swagger Docs Güncelleme
# Swagger dokümantasyonunu güncelle
swag init -g main.go
Database Migration
Uygulama ilk çalıştırıldığında otomatik olarak migration yapar ve seed data'yı ekler.
📝 Cache Service Kullanımı
cacheService := services.NewCacheService()
// Kullanıcı cache
cacheService.SetUser(userID, user, 1*time.Hour)
user, err := cacheService.GetUser(userID)
// Session
cacheService.SetSession(token, userID, 24*time.Hour)
userID, err := cacheService.GetSession(token)
// Rate limiting
count, err := cacheService.IncrementRateLimit("login:"+ip, 1*time.Minute)
// Token blacklist
cacheService.BlacklistToken(token, 24*time.Hour)
isBlacklisted, err := cacheService.IsTokenBlacklisted(token)
🤝 Contributing
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📄 License
This project is licensed under the MIT License.
👨💻 Author
GAuth-Central Team
⭐ Bu projeyi beğendiyseniz yıldız vermeyi unutmayın!
Description
Languages
Go
75.9%
Shell
19.6%
HTML
3.9%
Dockerfile
0.6%