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 "6. Test OAuth configuration:"
|
||||||
echo " cd /home/$CURRENT_USER/pdf-rename-sort"
|
echo " cd /home/$CURRENT_USER/pdf-rename-sort"
|
||||||
echo " source venv/bin/activate"
|
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 ""
|
||||||
echo "NOTE: This setup runs alongside your existing app on port 5000."
|
echo "NOTE: This setup runs alongside your existing app on port 5000."
|
||||||
echo "The PDF Renamer will be accessible at https://$DOMAIN_NAME."
|
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 os
|
||||||
import requests
|
import requests
|
||||||
|
import subprocess
|
||||||
from authlib.integrations.requests_client import OAuth2Session
|
from authlib.integrations.requests_client import OAuth2Session
|
||||||
|
|
||||||
def test_oauth_config():
|
def get_systemd_env_var(var_name):
|
||||||
# Get configuration from environment
|
"""Get environment variable from systemd service"""
|
||||||
tenant_id = os.getenv('TENANT_ID')
|
try:
|
||||||
client_id = os.getenv('CLIENT_ID')
|
result = subprocess.run(
|
||||||
client_secret = os.getenv('CLIENT_SECRET')
|
['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")
|
def test_oauth_config():
|
||||||
print("=" * 50)
|
# 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"TENANT_ID: {tenant_id}")
|
||||||
print(f"CLIENT_ID: {client_id}")
|
print(f"CLIENT_ID: {client_id}")
|
||||||
print(f"CLIENT_SECRET: {'*' * len(client_secret) if client_secret else 'None'}")
|
print(f"CLIENT_SECRET: {'*' * len(client_secret) if client_secret else 'None'}")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
if not all([tenant_id, client_id, client_secret]):
|
if not all([tenant_id, client_id, client_secret]):
|
||||||
print("❌ ERROR: Missing required environment variables!")
|
print("❌ ERROR: Missing required environment variables in systemd service!")
|
||||||
print("Make sure TENANT_ID, CLIENT_ID, and CLIENT_SECRET are set.")
|
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
|
return False
|
||||||
|
|
||||||
if tenant_id in ['your-tenant-id', 'YOUR_MICROSOFT_ENTRA_TENANT_ID']:
|
if tenant_id in ['your-tenant-id', 'YOUR_MICROSOFT_ENTRA_TENANT_ID']:
|
||||||
@@ -66,7 +91,7 @@ def test_oauth_config():
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
print()
|
print()
|
||||||
print("🎉 OAuth configuration appears to be correct!")
|
print("🎉 OAuth configuration in systemd service appears to be correct!")
|
||||||
print()
|
print()
|
||||||
print("Next steps:")
|
print("Next steps:")
|
||||||
print("1. Make sure your redirect URI is registered in Microsoft Entra:")
|
print("1. Make sure your redirect URI is registered in Microsoft Entra:")
|
||||||
|
|||||||
Reference in new issue
Block a user