entra auth test
This commit is contained in:
1 parent
5ed8131529
commit
baee94bcf7
3 files changed
+126
-8
No files matched your search
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to verify Microsoft Entra ID OAuth configuration
|
||||
Run this to check if your OAuth settings are correct before deploying.
|
||||
"""
|
||||
|
||||
import os
|
||||
import requests
|
||||
from authlib.integrations.requests_client import OAuth2Session
|
||||
|
||||
def test_oauth_config():
|
||||
# Get configuration from environment
|
||||
tenant_id = os.getenv('TENANT_ID')
|
||||
client_id = os.getenv('CLIENT_ID')
|
||||
client_secret = os.getenv('CLIENT_SECRET')
|
||||
|
||||
print("Testing Microsoft Entra ID OAuth Configuration")
|
||||
print("=" * 50)
|
||||
print(f"TENANT_ID: {tenant_id}")
|
||||
print(f"CLIENT_ID: {client_id}")
|
||||
print(f"CLIENT_SECRET: {'*' * len(client_secret) if client_secret else 'None'}")
|
||||
print()
|
||||
|
||||
if not all([tenant_id, client_id, client_secret]):
|
||||
print("❌ ERROR: Missing required environment variables!")
|
||||
print("Make sure TENANT_ID, CLIENT_ID, and CLIENT_SECRET are set.")
|
||||
return False
|
||||
|
||||
if tenant_id in ['your-tenant-id', 'YOUR_MICROSOFT_ENTRA_TENANT_ID']:
|
||||
print("❌ ERROR: TENANT_ID is still set to default placeholder value!")
|
||||
return False
|
||||
|
||||
if client_id in ['your-client-id', 'YOUR_MICROSOFT_ENTRA_CLIENT_ID']:
|
||||
print("❌ ERROR: CLIENT_ID is still set to default placeholder value!")
|
||||
return False
|
||||
|
||||
if client_secret in ['your-client-secret', 'YOUR_MICROSOFT_ENTRA_CLIENT_SECRET']:
|
||||
print("❌ ERROR: CLIENT_SECRET is still set to default placeholder value!")
|
||||
return False
|
||||
|
||||
# Test metadata URL
|
||||
metadata_url = f'https://login.microsoftonline.com/{tenant_id}/v2.0/.well-known/openid_configuration'
|
||||
print(f"Testing metadata URL: {metadata_url}")
|
||||
|
||||
try:
|
||||
response = requests.get(metadata_url, timeout=10)
|
||||
if response.status_code == 200:
|
||||
print("✅ Metadata URL is accessible")
|
||||
else:
|
||||
print(f"❌ Metadata URL returned status {response.status_code}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ Error accessing metadata URL: {e}")
|
||||
return False
|
||||
|
||||
# Test OAuth client creation
|
||||
try:
|
||||
client = OAuth2Session(
|
||||
client_id=client_id,
|
||||
client_secret=client_secret,
|
||||
scope=['openid', 'email', 'profile']
|
||||
)
|
||||
print("✅ OAuth client created successfully")
|
||||
except Exception as e:
|
||||
print(f"❌ Error creating OAuth client: {e}")
|
||||
return False
|
||||
|
||||
print()
|
||||
print("🎉 OAuth configuration appears to be correct!")
|
||||
print()
|
||||
print("Next steps:")
|
||||
print("1. Make sure your redirect URI is registered in Microsoft Entra:")
|
||||
print(" https://yourdomain.com/auth")
|
||||
print("2. Restart the application: sudo systemctl restart pdf-renamer")
|
||||
print("3. Check the application logs for any remaining issues")
|
||||
|
||||
return True
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_oauth_config()
|
||||
Reference in new issue
Block a user