entra auth test
This commit is contained in:
1 parent
5ed8131529
commit
baee94bcf7
3 files changed
+126
-8
No files matched your search
+26
-5
@@ -21,6 +21,10 @@ TENANT_ID = os.getenv('TENANT_ID', 'your-tenant-id')
|
||||
CLIENT_ID = os.getenv('CLIENT_ID', 'your-client-id')
|
||||
CLIENT_SECRET = os.getenv('CLIENT_SECRET', 'your-client-secret')
|
||||
|
||||
print(f"DEBUG: TENANT_ID = {TENANT_ID}")
|
||||
print(f"DEBUG: CLIENT_ID = {CLIENT_ID}")
|
||||
print(f"DEBUG: CLIENT_SECRET = {'*' * len(CLIENT_SECRET) if CLIENT_SECRET else 'None'}")
|
||||
|
||||
# Admin Configuration
|
||||
ADMIN_USERNAME = os.getenv('ADMIN_USERNAME', 'trbcit')
|
||||
ADMIN_PASSWORD = os.getenv('ADMIN_PASSWORD', 'atdrmbicn')
|
||||
@@ -31,7 +35,7 @@ microsoft = oauth.register(
|
||||
client_id=CLIENT_ID,
|
||||
client_secret=CLIENT_SECRET,
|
||||
server_metadata_url=f'https://login.microsoftonline.com/{TENANT_ID}/v2.0/.well-known/openid_configuration',
|
||||
client_kwargs={'scope': 'openid profile email'}
|
||||
client_kwargs={'scope': 'openid email profile'}
|
||||
)
|
||||
|
||||
def analyze_failed_extractions(log_path):
|
||||
@@ -650,6 +654,13 @@ def login():
|
||||
|
||||
@app.route('/entra-login')
|
||||
def entra_login():
|
||||
# Check if Microsoft Entra ID is configured
|
||||
if TENANT_ID in ['your-tenant-id', 'YOUR_MICROSOFT_ENTRA_TENANT_ID'] or \
|
||||
CLIENT_ID in ['your-client-id', 'YOUR_MICROSOFT_ENTRA_CLIENT_ID'] or \
|
||||
CLIENT_SECRET in ['your-client-secret', 'YOUR_MICROSOFT_ENTRA_CLIENT_SECRET']:
|
||||
flash('Microsoft Entra ID is not properly configured. Please check your environment variables.', 'error')
|
||||
return redirect(url_for('login'))
|
||||
|
||||
redirect_uri = url_for('auth', _external=True)
|
||||
return microsoft.authorize_redirect(redirect_uri)
|
||||
|
||||
@@ -684,10 +695,20 @@ def admin_login():
|
||||
|
||||
@app.route('/auth')
|
||||
def auth():
|
||||
token = microsoft.authorize_access_token()
|
||||
user = microsoft.parse_id_token(token)
|
||||
session['user'] = user
|
||||
return redirect(url_for('upload_files'))
|
||||
try:
|
||||
print("DEBUG: Starting OAuth callback processing")
|
||||
token = microsoft.authorize_access_token()
|
||||
print(f"DEBUG: Got token: {token}")
|
||||
user = microsoft.parse_id_token(token)
|
||||
print(f"DEBUG: Parsed user: {user}")
|
||||
session['user'] = user
|
||||
return redirect(url_for('upload_files'))
|
||||
except Exception as e:
|
||||
print(f"OAuth error: {e}") # Log the error for debugging
|
||||
import traceback
|
||||
print(f"Full traceback: {traceback.format_exc()}")
|
||||
flash('Authentication failed. Please check your Microsoft Entra ID configuration.', 'error')
|
||||
return redirect(url_for('login'))
|
||||
|
||||
@app.route('/logout')
|
||||
@login_required
|
||||
|
||||
Reference in new issue
Block a user