# 🔐 Social Authentication Setup & Test Guide ## ⚠️ Google OAuth Setup (ZORUNLU) Google ile login çalışması için callback URL'lerini Google Console'da eklemeniz gerekiyor: ### Adımlar: 1. **Google Cloud Console'a git:** https://console.cloud.google.com/apis/credentials 2. **Projenizi seçin** (veya yeni proje oluşturun) 3. **OAuth 2.0 Client ID'nize tıklayın:** - Client ID: `915364976256-691m0s87as2r5vdbqr96f6humblseobt.apps.googleusercontent.com` 4. **"Authorized redirect URIs" bölümüne şu URL'leri ekleyin:** ``` http://localhost:8000/api/v1/social/complete/google-oauth2/ http://localhost:8000/complete/google-oauth2/ http://127.0.0.1:8000/api/v1/social/complete/google-oauth2/ ``` 5. **"Authorized JavaScript origins" bölümüne:** ``` http://localhost:8000 http://127.0.0.1:8000 ``` 6. **Kaydet** butonuna tıklayın --- ## 🧪 Test Seçenekleri ### Seçenek 1: HTML Test Sayfası (ÖNERİLEN ✅) En kolay test yöntemi: ```bash # Tarayıcınızda açın: file:///home/beyhan/Python/server/templates/test_social_auth.html ``` **Veya:** 1. Dosya yöneticisinde `/home/beyhan/Python/server/templates/test_social_auth.html` dosyasına git 2. Çift tıkla (tarayıcıda açılır) 3. "Login with Google" butonuna tıkla --- ### Seçenek 2: Python Test Scripti Terminal'de interaktif test: ```bash cd /home/beyhan/Python/server source .venv/bin/activate python test_social_auth_manual.py ``` Bu script ile: - Google OAuth test edebilirsiniz (real token ile) - GitHub OAuth test edebilirsiniz --- ### Seçenek 3: Google OAuth Playground Gerçek access token almak için: 1. **Git:** https://developers.google.com/oauthplayground/ 2. **Settings (sağ üstte ⚙️):** - "Use your own OAuth credentials" seçeneğini aktif et - OAuth Client ID: `915364976256-691m0s87as2r5vdbqr96f6humblseobt.apps.googleusercontent.com` - OAuth Client secret: `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` 3. **Step 1 - Select & authorize APIs:** - Google OAuth2 API v2 seç - `https://www.googleapis.com/auth/userinfo.email` ✅ - `https://www.googleapis.com/auth/userinfo.profile` ✅ - "Authorize APIs" butonuna tıkla 4. **Step 2 - Exchange authorization code for tokens:** - "Exchange authorization code for tokens" butonuna tıkla - Access token kopyala 5. **Test et:** ```bash curl -X POST http://localhost:8000/api/v1/auth/social/google-oauth2/ \ -H "Content-Type: application/json" \ -d '{"access_token":""}' ``` --- ## 🐙 GitHub OAuth Setup GitHub için daha basit: ### Adımlar: 1. **GitHub Settings'e git:** https://github.com/settings/developers 2. **OAuth Apps'e tıkla** 3. **Uygulamanızı bul veya yeni oluştur:** - Application name: Django REST API Test - Homepage URL: `http://localhost:8000` - Authorization callback URL: `http://localhost:8000/api/v1/social/complete/github/` 4. **Client ID ve Client Secret'ı kontrol et:** - Client ID: `Ov23liUt9B61O46Mdfm4` - Client Secret: `c7fc8dcb1b2c8f22120608425d07d5efd995baaf` ### Test için Personal Access Token: Alternatif olarak, test için GitHub Personal Access Token kullanabilirsiniz: 1. **Git:** https://github.com/settings/tokens 2. **Generate new token (classic)** 3. **Scopes seç:** - `user` ✅ - `user:email` ✅ 4. **Token'ı oluştur ve kopyala** 5. **Test et:** ```bash curl -X POST http://localhost:8000/api/v1/auth/social/github/ \ -H "Content-Type: application/json" \ -d '{"access_token":""}' ``` --- ## ✅ Test Kontrolü Başarılı bir social login response'u şöyle görünmeli: ```json { "access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "user": { "id": 2, "email": "user@gmail.com", "first_name": "John", "last_name": "Doe", "is_active": true, "date_joined": "2025-12-12T22:00:00Z" } } ``` --- ## 🐛 Troubleshooting ### "redirect_uri_mismatch" hatası: - Google Console'da redirect URI'ları kontrol edin - Tam olarak `http://localhost:8000/api/v1/social/complete/google-oauth2/` olmalı ### "invalid_client" hatası: - Client ID ve Secret'ın doğru olduğundan emin olun - Google Console'da OAuth consent screen'i yapılandırdınız mı? ### "Email not provided" hatası: - OAuth scope'unda `userinfo.email` var mı kontrol edin - Provider settings'de email scope'u aktif mi? ### Server hatası: ```bash # Server çalıştığından emin olun: cd /home/beyhan/Python/server source .venv/bin/activate python manage.py runserver ``` ### Social auth view çalışmıyor: ```bash # URL'leri kontrol edin: curl http://localhost:8000/api/v1/auth/social/google-oauth2/ \ -X POST -H "Content-Type: application/json" \ -d '{"access_token":"test"}' # 400 Bad Request bekliyoruz (invalid token), 404 değil! ``` --- ## 📊 Test Checklist - [ ] Google Console'da redirect URI'lar eklendi - [ ] Django server çalışıyor (`python manage.py runserver`) - [ ] HTML test sayfası açılıyor - [ ] Google "Login" butonu çalışıyor - [ ] Access token alınıyor - [ ] Backend'e request gidiyor - [ ] JWT tokens dönüyor - [ ] User bilgileri görünüyor --- ## 🎯 Hızlı Test Komutu En hızlı test: ```bash # 1. Server'ı başlat (bir terminalde) cd /home/beyhan/Python/server source .venv/bin/activate python manage.py runserver # 2. Test scriptini çalıştır (başka terminalde) cd /home/beyhan/Python/server source .venv/bin/activate python test_social_auth_manual.py ``` Veya: ```bash # HTML sayfasını tarayıcıda aç: xdg-open /home/beyhan/Python/server/templates/test_social_auth.html ``` --- ## 📚 Daha Fazla Bilgi - **API Dokümantasyonu:** [AUTH.md](./AUTH.md) - **Genel Bakış:** [README.md](./README.md) - **Hızlı Başlangıç:** [QUICK_START.md](./QUICK_START.md) --- **İyi Testler! 🚀**