Beyhan Oğur bbbf76b184 first commit
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00
2026-04-26 21:35:24 +03:00

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 atahango

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 ı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şi
  • GET /v1/auth/verify-email - Email doğrulama
  • POST /v1/auth/refresh - Token yenileme
  • GET /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 getir
  • GET /v1/auth/validate - Token doğrulama

🗄️ Veritabanı Yapısı

PostgreSQL Tables

  • users - Kullanıcı bilgileri
  • social_accounts - OAuth hesap bağlantıları
  • roles - Kullanıcı rolleri
  • permissions - İzinler

Redis Cache Keys

  • user:{id} - Kullanıcı cache
  • session:{token} - Session yönetimi
  • blacklist:{token} - Token blacklist
  • ratelimit:{key} - Rate limiting
  • email_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:

  1. PostgreSQL - Ana veritabanı (Port: 5432)
  2. Redis - Cache ve session store (Port: 6379)
  3. 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

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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
No description provided
Readme 2.4 MiB
Languages
JavaScript 72%
CSS 12.1%
TypeScript 9.8%
Go 5.6%
Shell 0.4%