Skip to content

Commit 4a9d879

Browse files
better logging
1 parent 1ca3143 commit 4a9d879

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

app/routes.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,31 @@ def oidc_callback():
10361036
user_info = token.get('userinfo')
10371037
if not user_info:
10381038
# Try to get userinfo from the token
1039-
user_info = oidc_client.parse_id_token(token)
1039+
try:
1040+
user_info = oidc_client.parse_id_token(token)
1041+
except Exception as parse_error:
1042+
current_app.logger.error(f"Failed to parse ID token: {parse_error}")
1043+
# Try fetching userinfo from endpoint if available
1044+
if oidc_config.userinfo_endpoint:
1045+
try:
1046+
import requests
1047+
access_token = token.get('access_token')
1048+
if access_token:
1049+
response = requests.get(
1050+
oidc_config.userinfo_endpoint,
1051+
headers={'Authorization': f'Bearer {access_token}'},
1052+
timeout=10
1053+
)
1054+
if response.status_code == 200:
1055+
user_info = response.json()
1056+
else:
1057+
current_app.logger.error(f"UserInfo endpoint returned {response.status_code}: {response.text}")
1058+
except Exception as userinfo_error:
1059+
current_app.logger.error(f"Failed to fetch userinfo: {userinfo_error}")
1060+
1061+
if not user_info:
1062+
flash('Failed to retrieve user information from identity provider.', 'error')
1063+
return redirect(url_for('main.login'))
10401064

10411065
# Get mapping configuration from session
10421066
mapping_field = session.get('oidc_mapping_field', 'email')
@@ -1099,6 +1123,6 @@ def oidc_callback():
10991123
return redirect(url_for('main.dashboard'))
11001124

11011125
except Exception as e:
1102-
current_app.logger.error(f"Error in OIDC callback: {e}")
1103-
flash('An error occurred during login. Please try again or contact your administrator.', 'error')
1126+
current_app.logger.error(f"Error in OIDC callback: {e}", exc_info=True)
1127+
flash(f'An error occurred during login: {str(e)}. Please try again or contact your administrator.', 'error')
11041128
return redirect(url_for('main.login'))

0 commit comments

Comments
 (0)