first commit
This commit is contained in:
190
test_social_auth_manual.py
Normal file
190
test_social_auth_manual.py
Normal file
@@ -0,0 +1,190 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Manual Social Auth Test Script
|
||||
|
||||
Bu script ile social authentication'ı test edebilirsiniz.
|
||||
Gerçek bir access token ile test yapar.
|
||||
"""
|
||||
import requests
|
||||
import json
|
||||
|
||||
BASE_URL = "http://localhost:8000/api/v1"
|
||||
|
||||
def print_header(title):
|
||||
print(f"\n{'='*60}")
|
||||
print(f" {title}")
|
||||
print(f"{'='*60}\n")
|
||||
|
||||
def print_response(response):
|
||||
print(f"Status Code: {response.status_code}")
|
||||
try:
|
||||
data = response.json()
|
||||
print(f"Response:\n{json.dumps(data, indent=2)}")
|
||||
except:
|
||||
print(f"Response: {response.text}")
|
||||
|
||||
def test_google_oauth():
|
||||
"""
|
||||
Google OAuth Test
|
||||
|
||||
Gerçek test için:
|
||||
1. Google OAuth Playground'a git: https://developers.google.com/oauthplayground/
|
||||
2. Scopes seç:
|
||||
- https://www.googleapis.com/auth/userinfo.email
|
||||
- https://www.googleapis.com/auth/userinfo.profile
|
||||
3. "Authorize APIs" tıkla
|
||||
4. Access token'ı kopyala
|
||||
5. Aşağıdaki token yerine yapıştır
|
||||
"""
|
||||
print_header("🔵 Google OAuth Test")
|
||||
|
||||
# ⚠️ Buraya gerçek Google access token yapıştırın
|
||||
access_token = input("Google Access Token girin (veya Enter ile atla): ").strip()
|
||||
|
||||
if not access_token:
|
||||
print("❌ Access token girilmedi. Atlaniyor...")
|
||||
print("\n📝 Google token almak için:")
|
||||
print(" 1. https://developers.google.com/oauthplayground/")
|
||||
print(" 2. Settings (sağ üst) → Use your own OAuth credentials")
|
||||
print(" 3. Client ID: 915364976256-691m0s87as2r5vdbqr96f6humblseobt.apps.googleusercontent.com")
|
||||
print(" 4. Client Secret: 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")
|
||||
print(" 5. Scopes: userinfo.email, userinfo.profile")
|
||||
print(" 6. Authorize APIs → Exchange authorization code for tokens")
|
||||
return
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{BASE_URL}/auth/social/google-oauth2/",
|
||||
json={"access_token": access_token},
|
||||
headers={"Content-Type": "application/json"}
|
||||
)
|
||||
|
||||
print_response(response)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("\n✅ Google OAuth Başarılı!")
|
||||
data = response.json()
|
||||
if 'user' in data:
|
||||
print(f"\n👤 User: {data['user']['email']}")
|
||||
print(f"🔑 Access Token alındı: {data['access'][:50]}...")
|
||||
else:
|
||||
print("\n❌ Google OAuth Başarısız!")
|
||||
|
||||
except requests.exceptions.ConnectionError:
|
||||
print("❌ Server'a bağlanılamadı. Server çalışıyor mu?")
|
||||
print(" python manage.py runserver")
|
||||
except Exception as e:
|
||||
print(f"❌ Hata: {e}")
|
||||
|
||||
def test_github_oauth():
|
||||
"""
|
||||
GitHub OAuth Test
|
||||
|
||||
Gerçek test için:
|
||||
1. GitHub'da Personal Access Token oluştur
|
||||
2. Scopes: user, user:email
|
||||
3. Token'ı aşağıya yapıştır
|
||||
"""
|
||||
print_header("⚫ GitHub OAuth Test")
|
||||
|
||||
# ⚠️ Buraya gerçek GitHub access token yapıştırın
|
||||
access_token = input("GitHub Access Token girin (veya Enter ile atla): ").strip()
|
||||
|
||||
if not access_token:
|
||||
print("❌ Access token girilmedi. Atlanıyor...")
|
||||
print("\n📝 GitHub token almak için:")
|
||||
print(" 1. https://github.com/settings/tokens")
|
||||
print(" 2. Generate new token (classic)")
|
||||
print(" 3. Scopes: user, user:email")
|
||||
print(" 4. Token'ı kopyala")
|
||||
return
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{BASE_URL}/auth/social/github/",
|
||||
json={"access_token": access_token},
|
||||
headers={"Content-Type": "application/json"}
|
||||
)
|
||||
|
||||
print_response(response)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("\n✅ GitHub OAuth Başarılı!")
|
||||
data = response.json()
|
||||
if 'user' in data:
|
||||
print(f"\n👤 User: {data['user']['email']}")
|
||||
print(f"🔑 Access Token alındı: {data['access'][:50]}...")
|
||||
else:
|
||||
print("\n❌ GitHub OAuth Başarısız!")
|
||||
|
||||
except requests.exceptions.ConnectionError:
|
||||
print("❌ Server'a bağlanılamadı. Server çalışıyor mu?")
|
||||
print(" python manage.py runserver")
|
||||
except Exception as e:
|
||||
print(f"❌ Hata: {e}")
|
||||
|
||||
def test_endpoints_available():
|
||||
"""Check if social auth endpoints are available"""
|
||||
print_header("🔍 Endpoint Kontrolü")
|
||||
|
||||
try:
|
||||
# Test if server is running
|
||||
response = requests.get(f"{BASE_URL}/auth/users/")
|
||||
print("✅ Server çalışıyor")
|
||||
|
||||
# Social auth endpoints don't support GET, so we expect 405
|
||||
print("✅ Social auth endpoints hazır")
|
||||
|
||||
except requests.exceptions.ConnectionError:
|
||||
print("❌ Server çalışmıyor!")
|
||||
print(" Çalıştırmak için: python manage.py runserver")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"⚠️ Beklenmeyen hata: {e}")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def main():
|
||||
print("\n" + "="*60)
|
||||
print(" 🔐 Django Social Auth Test Script")
|
||||
print("="*60)
|
||||
print("\n📝 Bu script ile Google ve GitHub OAuth'u test edebilirsiniz.")
|
||||
print(" Real access token'larla çalışır.\n")
|
||||
|
||||
# Check if server is running
|
||||
if not test_endpoints_available():
|
||||
return
|
||||
|
||||
while True:
|
||||
print("\n" + "-"*60)
|
||||
print("Seçenekler:")
|
||||
print(" 1. Google OAuth Test")
|
||||
print(" 2. GitHub OAuth Test")
|
||||
print(" 3. HTML Test Sayfasını Aç")
|
||||
print(" 4. Çıkış")
|
||||
print("-"*60)
|
||||
|
||||
choice = input("\nSeçiminiz (1-4): ").strip()
|
||||
|
||||
if choice == "1":
|
||||
test_google_oauth()
|
||||
elif choice == "2":
|
||||
test_github_oauth()
|
||||
elif choice == "3":
|
||||
print("\n📄 HTML test sayfası:")
|
||||
print(" file:///home/beyhan/Python/server/templates/test_social_auth.html")
|
||||
print("\n veya tarayıcınızda açın:")
|
||||
print(" Dosya → Aç → /home/beyhan/Python/server/templates/test_social_auth.html")
|
||||
elif choice == "4":
|
||||
print("\n👋 Çıkılıyor...")
|
||||
break
|
||||
else:
|
||||
print("❌ Geçersiz seçim!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
print("\n\n👋 Test sonlandırıldı.")
|
||||
|
||||
Reference in New Issue
Block a user