5.8 KiB
🔐 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:
-
Google Cloud Console'a git: https://console.cloud.google.com/apis/credentials
-
Projenizi seçin (veya yeni proje oluşturun)
-
OAuth 2.0 Client ID'nize tıklayın:
- Client ID:
915364976256-691m0s87as2r5vdbqr96f6humblseobt.apps.googleusercontent.com
- Client ID:
-
"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/ -
"Authorized JavaScript origins" bölümüne:
http://localhost:8000 http://127.0.0.1:8000 -
Kaydet butonuna tıklayın
🧪 Test Seçenekleri
Seçenek 1: HTML Test Sayfası (ÖNERİLEN ✅)
En kolay test yöntemi:
# Tarayıcınızda açın:
file:///home/beyhan/Python/server/templates/test_social_auth.html
Veya:
- Dosya yöneticisinde
/home/beyhan/Python/server/templates/test_social_auth.htmldosyasına git - Çift tıkla (tarayıcıda açılır)
- "Login with Google" butonuna tıkla
Seçenek 2: Python Test Scripti
Terminal'de interaktif test:
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:
-
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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
-
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
-
Step 2 - Exchange authorization code for tokens:
- "Exchange authorization code for tokens" butonuna tıkla
- Access token kopyala
-
Test et:
curl -X POST http://localhost:8000/api/v1/auth/social/google-oauth2/ \ -H "Content-Type: application/json" \ -d '{"access_token":"<BURAYA_TOKEN_YAPIŞTIR>"}'
🐙 GitHub OAuth Setup
GitHub için daha basit:
Adımlar:
-
GitHub Settings'e git: https://github.com/settings/developers
-
OAuth Apps'e tıkla
-
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/
-
Client ID ve Client Secret'ı kontrol et:
- Client ID:
Ov23liUt9B61O46Mdfm4 - Client Secret:
c7fc8dcb1b2c8f22120608425d07d5efd995baaf
- Client ID:
Test için Personal Access Token:
Alternatif olarak, test için GitHub Personal Access Token kullanabilirsiniz:
- Git: https://github.com/settings/tokens
- Generate new token (classic)
- Scopes seç:
user✅user:email✅
- Token'ı oluştur ve kopyala
- Test et:
curl -X POST http://localhost:8000/api/v1/auth/social/github/ \ -H "Content-Type: application/json" \ -d '{"access_token":"<GITHUB_TOKEN>"}'
✅ Test Kontrolü
Başarılı bir social login response'u şöyle görünmeli:
{
"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.emailvar mı kontrol edin - Provider settings'de email scope'u aktif mi?
Server hatası:
# 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:
# 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:
# 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:
# 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
- Genel Bakış: README.md
- Hızlı Başlangıç: QUICK_START.md
İyi Testler! 🚀