Fix OAuth by using userinfo from token instead of parse_id_token
This commit is contained in:
1 parent
db5df8575f
commit
40f65be11b
1 file changed
+22
-4
+22
-4
@@ -731,15 +731,33 @@ def auth():
|
|||||||
print("DEBUG: Starting OAuth callback processing")
|
print("DEBUG: Starting OAuth callback processing")
|
||||||
token = microsoft.authorize_access_token()
|
token = microsoft.authorize_access_token()
|
||||||
print(f"DEBUG: Got token: {token}")
|
print(f"DEBUG: Got token: {token}")
|
||||||
user = microsoft.parse_id_token(token)
|
|
||||||
print(f"DEBUG: Parsed user: {user}")
|
# Get user info from the token's userinfo (already parsed by Authlib)
|
||||||
session['user'] = user
|
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'))
|
return redirect(url_for('upload_files'))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"OAuth error: {e}") # Log the error for debugging
|
print(f"OAuth error: {e}") # Log the error for debugging
|
||||||
import traceback
|
import traceback
|
||||||
print(f"Full traceback: {traceback.format_exc()}")
|
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'))
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
@app.route('/logout')
|
@app.route('/logout')
|
||||||
|
|||||||
Reference in new issue
Block a user