@server.before_request
def auth_and_logging_middleware():
"""Combined authentication check and request logging"""
# Log incoming requests for debugging
if logger:
logger.debug(f"MIDDLEWARE: Request to {flask_request.path} from {flask_request.remote_addr}")
logger.debug(f"Headers: {dict(flask_request.headers)}")
logger.debug(f"Cookies: {list(flask_request.cookies.keys())}")
if hasattr(flask_request, 'cookies') and 'colosseum_auth' in flask_request.cookies:
logger.debug(f"Found colosseum_auth cookie: {flask_request.cookies.get('colosseum_auth')[:50]}...")
# Only enforce authentication for GET requests to the exact root path '/'
if flask_request.method == 'GET' and flask_request.path == '/':
if logger:
logger.info(f"MIDDLEWARE: Checking authentication for root path request from {flask_request.remote_addr}")
# Check authentication only when needed (for root path)
is_authenticated, user_ntid = get_user_info()
if not is_authenticated:
if logger:
logger.info(f"MIDDLEWARE: Redirecting unauthenticated user from {flask_request.path} to: {login_url}/?module=dashdemo")
return redirect(f"{login_url}/?module=dashdemo", code=302)
else:
if logger:
logger.info(f"MIDDLEWARE: User {user_ntid} authenticated for root path - allowing request")
return None # Add this return statement to prevent further execution
else:
# Allow ALL other requests (including POST callbacks and Dash assets) to pass through
logger.info(f" Flask request path: {flask_request.path}")
if logger and (flask_request.path.startswith('/_dash') or flask_request.path.startswith('/dashdemo/_dash')):
logger.info(f"MIDDLEWARE: Allowing Dash asset request: {flask_request.path}")
elif logger:
logger.debug(f"MIDDLEWARE: Allowing {flask_request.method} request to {flask_request.path} without auth check")
return None
Dash is running on http://0.0.0.0:8501/
* Serving Flask app 'app'
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:8501
* Running on http://10.128.18.246:8501
Press CTRL+C to quit
2025-11-02 09:10:41,876 - dashdemo_a8dd538d - DEBUG - 🔥 MIDDLEWARE: Request to / from 10.129.8.79
2025-11-02 09:10:41,877 - dashdemo_a8dd538d - DEBUG - Headers: {'Host': ...
2025-11-02 09:10:41,877 - dashdemo_a8dd538d - INFO - 🔥 MIDDLEWARE: Checking authentication for root path request from 10.129.8.79
2025-11-02 09:10:41,877 - dashdemo_a8dd538d - DEBUG - Available cookies: ['ajs_anonymous_id', '_BEAMER_USER_ID_cVbYMFmN65374', '_BEAMER_FIRST_VISIT_cVbYMFmN65374', '_gcl_au', '_ga', '_ga_4EZXK105K9', '_hp5_event_props.1502104954', '_hp5_meta.1502104954', '_hp5_let.1502104954', 'session', '_streamlit_xsrf']
2025-11-02 09:10:41,877 - dashdemo_a8dd538d - DEBUG - No colosseum_auth cookie found - user needs to authenticate
2025-11-02 09:10:41,877 - dashdemo_a8dd538d - INFO - 🔥 MIDDLEWARE: Redirecting unauthenticated user from / to: .../?module=dashdemo
10.129.8.79 - - [02/Nov/2025 09:10:41] "GET / HTTP/1.1" 302 -
2025-11-02 09:10:44,533 - dashdemo_a8dd538d - DEBUG - 🔥 MIDDLEWARE: Request to / from 10.129.8.79
2025-11-02 09:10:44,534 - dashdemo_a8dd538d - DEBUG - Headers: {'Host': ...
2025-11-02 09:10:44,534 - dashdemo_a8dd538d - DEBUG - Cookies: ['ajs_anonymous_id', '_BEAMER_USER_ID_cVbYMFmN65374', '_BEAMER_FIRST_VISIT_cVbYMFmN65374', '_gcl_au', '_ga', '_ga_4EZXK105K9', '_hp5_event_props.1502104954', '_hp5_meta.1502104954', '_hp5_let.1502104954', 'session', '_streamlit_xsrf', 'correct_auth']
2025-11-02 09:10:44,534 - dashdemo_a8dd538d - DEBUG - Found correct_auth cookie: Z0FBQU...
2025-11-02 09:10:44,534 - dashdemo_a8dd538d - INFO - 🔥 MIDDLEWARE: Checking authentication for root path request from 10.129.8.79
2025-11-02 09:10:44,534 - dashdemo_a8dd538d - DEBUG - Available cookies: ['ajs_anonymous_id', '_BEAMER_USER_ID_cVbYMFmN65374', '_BEAMER_FIRST_VISIT_cVbYMFmN65374', '_gcl_au', '_ga', '_ga_4EZXK105K9', '_hp5_event_props.1502104954', '_hp5_meta.1502104954', '_hp5_let.1502104954', 'session', '_streamlit_xsrf', 'correct_auth']
2025-11-02 09:10:44,534 - dashdemo_a8dd538d - DEBUG - Found correct_auth cookie (length: 304)
2025-11-02 09:10:44,534 - dashdemo_a8dd538d - DEBUG - Attempting to decrypt correct_auth cookie
2025-11-02 09:10:44,542 - dashdemo_a8dd538d - DEBUG - Successfully decrypted cookie: [...
2025-11-02 09:10:44,542 - dashdemo_a8dd538d - INFO - Authenticated user xxx with 9 AD groups
2025-11-02 09:10:44,542 - dashdemo_a8dd538d - DEBUG - AD groups: ...
2025-11-02 09:10:44,542 - dashdemo_a8dd538d - INFO - 🔥 MIDDLEWARE: User xxx authenticated for root path - allowing request
10.129.8.79 - - [02/Nov/2025 09:10:44] "GET / HTTP/1.1" 200 -
логи здесь застревают... он должен продолжить рендеринг макета тире, но почему? кажется, моя аутентификация прошла правильно, но обратные вызовы не работают?? в чем может быть проблема помогите пожалуйста. пытаюсь развернуть это приложение, но на странице просто отображается «Загрузка...» в верхнем левом углу без рендеринга HTML
моя аутентификация [code] @server.before_request def auth_and_logging_middleware(): """Combined authentication check and request logging""" # Log incoming requests for debugging if logger: logger.debug(f"MIDDLEWARE: Request to {flask_request.path} from {flask_request.remote_addr}") logger.debug(f"Headers: {dict(flask_request.headers)}") logger.debug(f"Cookies: {list(flask_request.cookies.keys())}") if hasattr(flask_request, 'cookies') and 'colosseum_auth' in flask_request.cookies: logger.debug(f"Found colosseum_auth cookie: {flask_request.cookies.get('colosseum_auth')[:50]}...")
# Only enforce authentication for GET requests to the exact root path '/' if flask_request.method == 'GET' and flask_request.path == '/': if logger: logger.info(f"MIDDLEWARE: Checking authentication for root path request from {flask_request.remote_addr}")
# Check authentication only when needed (for root path) is_authenticated, user_ntid = get_user_info()
if not is_authenticated: if logger: logger.info(f"MIDDLEWARE: Redirecting unauthenticated user from {flask_request.path} to: {login_url}/?module=dashdemo") return redirect(f"{login_url}/?module=dashdemo", code=302) else: if logger: logger.info(f"MIDDLEWARE: User {user_ntid} authenticated for root path - allowing request") return None # Add this return statement to prevent further execution
else: # Allow ALL other requests (including POST callbacks and Dash assets) to pass through logger.info(f" Flask request path: {flask_request.path}") if logger and (flask_request.path.startswith('/_dash') or flask_request.path.startswith('/dashdemo/_dash')): logger.info(f"MIDDLEWARE: Allowing Dash asset request: {flask_request.path}") elif logger: logger.debug(f"MIDDLEWARE: Allowing {flask_request.method} request to {flask_request.path} without auth check")
return None [/code] мои журналы [code]Dash is running on http://0.0.0.0:8501/ * Serving Flask app 'app' * Debug mode: off WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on all addresses (0.0.0.0) * Running on http://127.0.0.1:8501 * Running on http://10.128.18.246:8501 Press CTRL+C to quit 2025-11-02 09:10:41,876 - dashdemo_a8dd538d - DEBUG - 🔥 MIDDLEWARE: Request to / from 10.129.8.79 2025-11-02 09:10:41,877 - dashdemo_a8dd538d - DEBUG - Headers: {'Host': ... 2025-11-02 09:10:41,877 - dashdemo_a8dd538d - INFO - 🔥 MIDDLEWARE: Checking authentication for root path request from 10.129.8.79 2025-11-02 09:10:41,877 - dashdemo_a8dd538d - DEBUG - Available cookies: ['ajs_anonymous_id', '_BEAMER_USER_ID_cVbYMFmN65374', '_BEAMER_FIRST_VISIT_cVbYMFmN65374', '_gcl_au', '_ga', '_ga_4EZXK105K9', '_hp5_event_props.1502104954', '_hp5_meta.1502104954', '_hp5_let.1502104954', 'session', '_streamlit_xsrf'] 2025-11-02 09:10:41,877 - dashdemo_a8dd538d - DEBUG - No colosseum_auth cookie found - user needs to authenticate 2025-11-02 09:10:41,877 - dashdemo_a8dd538d - INFO - 🔥 MIDDLEWARE: Redirecting unauthenticated user from / to: .../?module=dashdemo 10.129.8.79 - - [02/Nov/2025 09:10:41] "GET / HTTP/1.1" 302 - 2025-11-02 09:10:44,533 - dashdemo_a8dd538d - DEBUG - 🔥 MIDDLEWARE: Request to / from 10.129.8.79 2025-11-02 09:10:44,534 - dashdemo_a8dd538d - DEBUG - Headers: {'Host': ... 2025-11-02 09:10:44,534 - dashdemo_a8dd538d - DEBUG - Cookies: ['ajs_anonymous_id', '_BEAMER_USER_ID_cVbYMFmN65374', '_BEAMER_FIRST_VISIT_cVbYMFmN65374', '_gcl_au', '_ga', '_ga_4EZXK105K9', '_hp5_event_props.1502104954', '_hp5_meta.1502104954', '_hp5_let.1502104954', 'session', '_streamlit_xsrf', 'correct_auth'] 2025-11-02 09:10:44,534 - dashdemo_a8dd538d - DEBUG - Found correct_auth cookie: Z0FBQU... 2025-11-02 09:10:44,534 - dashdemo_a8dd538d - INFO - 🔥 MIDDLEWARE: Checking authentication for root path request from 10.129.8.79 2025-11-02 09:10:44,534 - dashdemo_a8dd538d - DEBUG - Available cookies: ['ajs_anonymous_id', '_BEAMER_USER_ID_cVbYMFmN65374', '_BEAMER_FIRST_VISIT_cVbYMFmN65374', '_gcl_au', '_ga', '_ga_4EZXK105K9', '_hp5_event_props.1502104954', '_hp5_meta.1502104954', '_hp5_let.1502104954', 'session', '_streamlit_xsrf', 'correct_auth'] 2025-11-02 09:10:44,534 - dashdemo_a8dd538d - DEBUG - Found correct_auth cookie (length: 304) 2025-11-02 09:10:44,534 - dashdemo_a8dd538d - DEBUG - Attempting to decrypt correct_auth cookie 2025-11-02 09:10:44,542 - dashdemo_a8dd538d - DEBUG - Successfully decrypted cookie: [... 2025-11-02 09:10:44,542 - dashdemo_a8dd538d - INFO - Authenticated user xxx with 9 AD groups 2025-11-02 09:10:44,542 - dashdemo_a8dd538d - DEBUG - AD groups: ... 2025-11-02 09:10:44,542 - dashdemo_a8dd538d - INFO - 🔥 MIDDLEWARE: User xxx authenticated for root path - allowing request 10.129.8.79 - - [02/Nov/2025 09:10:44] "GET / HTTP/1.1" 200 - [/code] логи здесь застревают... он должен продолжить рендеринг макета тире, но почему? кажется, моя аутентификация прошла правильно, но обратные вызовы не работают?? в чем может быть проблема помогите пожалуйста. пытаюсь развернуть это приложение, но на странице просто отображается «Загрузка...» в верхнем левом углу без рендеринга HTML