Auto login with Authelia
This commit is contained in:
32
app.py
32
app.py
@@ -290,30 +290,14 @@ def logout():
|
|||||||
# Clear local session
|
# Clear local session
|
||||||
session.clear()
|
session.clear()
|
||||||
|
|
||||||
# If user was authenticated via Authelia, try to redirect to Authelia logout
|
# If user was authenticated via Authelia, redirect to app login (not Authelia logout)
|
||||||
if auth_method == 'authelia' or authelia_user:
|
# This keeps the Authelia session active for other apps
|
||||||
# Look for Authelia URL in headers
|
if ENABLE_PROXY and (auth_method == 'authelia' or authelia_user):
|
||||||
authelia_url = request.headers.get('X-Authelia-URL')
|
logger.info(f"Logout for Authelia user - redirecting to app login page")
|
||||||
|
# Just redirect back to login page - Authelia session stays active
|
||||||
# If found, redirect to Authelia logout
|
response = redirect(url_for('login'))
|
||||||
if authelia_url:
|
response.set_cookie(app.config['SESSION_COOKIE_NAME'], '', expires=0)
|
||||||
logger.info(f"Redirecting to Authelia logout: {authelia_url}/logout")
|
return response
|
||||||
return redirect(f"{authelia_url}/logout")
|
|
||||||
|
|
||||||
# Try some common authelia URLs based on the request
|
|
||||||
if request.host:
|
|
||||||
domain_parts = request.host.split('.')
|
|
||||||
if len(domain_parts) >= 2:
|
|
||||||
base_domain = '.'.join(domain_parts[1:]) # e.g., extract 'example.com' from 'app.example.com'
|
|
||||||
common_authelia_urls = [
|
|
||||||
f"https://auth.{base_domain}/logout",
|
|
||||||
f"https://authelia.{base_domain}/logout",
|
|
||||||
f"https://sso.{base_domain}/logout"
|
|
||||||
]
|
|
||||||
|
|
||||||
# Try the first one as a fallback
|
|
||||||
logger.info(f"No Authelia URL header, trying fallback: {common_authelia_urls[0]}")
|
|
||||||
return redirect(common_authelia_urls[0])
|
|
||||||
|
|
||||||
# Default case: redirect to login page
|
# Default case: redirect to login page
|
||||||
response = redirect(url_for('login'))
|
response = redirect(url_for('login'))
|
||||||
|
|||||||
Reference in New Issue
Block a user