test auth
This commit is contained in:
1 parent
baee94bcf7
commit
259f71bceb
2 files changed
+36
-11
No files matched your search
@@ -287,7 +287,7 @@ echo ""
|
||||
echo "6. Test OAuth configuration:"
|
||||
echo " cd /home/$CURRENT_USER/pdf-rename-sort"
|
||||
echo " source venv/bin/activate"
|
||||
echo " python test_oauth_config.py"
|
||||
echo " python3 test_oauth_config.py # This checks systemd service environment variables"
|
||||
echo ""
|
||||
echo "NOTE: This setup runs alongside your existing app on port 5000."
|
||||
echo "The PDF Renamer will be accessible at https://$DOMAIN_NAME."
|
||||
|
||||
+35
-10
@@ -6,24 +6,49 @@ Run this to check if your OAuth settings are correct before deploying.
|
||||
|
||||
import os
|
||||
import requests
|
||||
import subprocess
|
||||
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')
|
||||
def get_systemd_env_var(var_name):
|
||||
"""Get environment variable from systemd service"""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
['systemctl', 'show', 'pdf-renamer', '-p', f'Environment'],
|
||||
capture_output=True, text=True, check=True
|
||||
)
|
||||
env_lines = result.stdout.strip().split('\n')
|
||||
for line in env_lines:
|
||||
if f'{var_name}=' in line:
|
||||
# Extract the value after the equals sign
|
||||
return line.split('=', 1)[1].strip('"')
|
||||
return None
|
||||
except subprocess.CalledProcessError:
|
||||
return None
|
||||
|
||||
print("Testing Microsoft Entra ID OAuth Configuration")
|
||||
print("=" * 50)
|
||||
def test_oauth_config():
|
||||
# Get configuration from systemd service environment
|
||||
tenant_id = get_systemd_env_var('TENANT_ID')
|
||||
client_id = get_systemd_env_var('CLIENT_ID')
|
||||
client_secret = get_systemd_env_var('CLIENT_SECRET')
|
||||
|
||||
print("Testing Microsoft Entra ID OAuth Configuration (from systemd service)")
|
||||
print("=" * 60)
|
||||
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.")
|
||||
print("❌ ERROR: Missing required environment variables in systemd service!")
|
||||
print("The PDF renamer service doesn't have the Microsoft Entra credentials set.")
|
||||
print()
|
||||
print("To fix this:")
|
||||
print("1. Edit the service file: sudo nano /etc/systemd/system/pdf-renamer.service")
|
||||
print("2. Add these lines in the [Service] section:")
|
||||
print(" Environment=\"TENANT_ID=your-tenant-id\"")
|
||||
print(" Environment=\"CLIENT_ID=your-client-id\"")
|
||||
print(" Environment=\"CLIENT_SECRET=your-client-secret\"")
|
||||
print("3. Reload and restart: sudo systemctl daemon-reload && sudo systemctl restart pdf-renamer")
|
||||
return False
|
||||
|
||||
if tenant_id in ['your-tenant-id', 'YOUR_MICROSOFT_ENTRA_TENANT_ID']:
|
||||
@@ -66,7 +91,7 @@ def test_oauth_config():
|
||||
return False
|
||||
|
||||
print()
|
||||
print("🎉 OAuth configuration appears to be correct!")
|
||||
print("🎉 OAuth configuration in systemd service appears to be correct!")
|
||||
print()
|
||||
print("Next steps:")
|
||||
print("1. Make sure your redirect URI is registered in Microsoft Entra:")
|
||||
|
||||
Reference in new issue
Block a user