From 259f71bceb8fabb0390d7f5f7e5fe6498a2cb95e Mon Sep 17 00:00:00 2001 From: nmemmert <67961292+nmemmert@users.noreply.github.com> Date: Thu, 6 Nov 2025 15:53:28 -0500 Subject: [PATCH] test auth --- nextgenpdf-install.sh | 2 +- test_oauth_config.py | 45 +++++++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/nextgenpdf-install.sh b/nextgenpdf-install.sh index 866783a..57b4938 100644 --- a/nextgenpdf-install.sh +++ b/nextgenpdf-install.sh @@ -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." diff --git a/test_oauth_config.py b/test_oauth_config.py index 289a90d..5e00753 100644 --- a/test_oauth_config.py +++ b/test_oauth_config.py @@ -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:")