Fix OAuth by using userinfo from token instead of parse_id_token

This commit is contained in:
nmemmert committed 2025-11-06 16:22:42 -05:00
1 parent db5df8575f
commit 40f65be11b
1 file changed
+22 -4
+22 -4
View File
@@ -731,15 +731,33 @@ def auth():
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
# Get user info from the token's userinfo (already parsed by Authlib)
user_info = token.get('userinfo')
if not user_info:
print("ERROR: No userinfo in token")
flash('Failed to get user information from Microsoft.', 'error')
return redirect(url_for('login'))
print(f"DEBUG: Parsed user info: {user_info}")
# Store user information in session
session['user'] = {
'name': user_info.get('name', 'Unknown'),
'email': user_info.get('email') or user_info.get('preferred_username', 'unknown@example.com'),
'oid': user_info.get('oid'),
}
session.permanent = True
print(f"DEBUG: User logged in successfully: {session['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')
flash('Authentication failed. Please try again.', 'error')
return redirect(url_for('login'))
@app.route('/logout')