mirror of
https://github.com/zvx-echo6/recon.git
synced 2026-05-20 06:34:40 +02:00
feat: add /api/auth/whoami endpoint for frontend auth state
Returns {authenticated: bool, username: string|null} based on
X-Authentik-Username header presence. Used by Navi frontend to
detect auth state without triggering SSO redirect.
This commit is contained in:
parent
b5de9c6e39
commit
121eb45b44
1 changed files with 18 additions and 0 deletions
18
lib/api.py
18
lib/api.py
|
|
@ -2704,3 +2704,21 @@ def api_metrics_history():
|
||||||
return jsonify({'type': metric_type, 'hours': hours, 'points': points})
|
return jsonify({'type': metric_type, 'hours': hours, 'points': points})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'type': metric_type, 'hours': hours, 'points': [], 'error': str(e)})
|
return jsonify({'type': metric_type, 'hours': hours, 'points': [], 'error': str(e)})
|
||||||
|
|
||||||
|
|
||||||
|
# ── Auth state endpoint ─────────────────────────────────────────────────────
|
||||||
|
# Returns current auth state for frontend consumption.
|
||||||
|
# This endpoint must be behind Caddy forward_auth to receive X-Authentik-* headers.
|
||||||
|
@app.route('/api/auth/whoami')
|
||||||
|
def api_auth_whoami():
|
||||||
|
"""Return auth state for frontend. Behind forward_auth, so headers are present when authenticated."""
|
||||||
|
username = request.headers.get('X-Authentik-Username')
|
||||||
|
if username:
|
||||||
|
return jsonify({
|
||||||
|
'authenticated': True,
|
||||||
|
'username': username,
|
||||||
|
})
|
||||||
|
return jsonify({
|
||||||
|
'authenticated': False,
|
||||||
|
'username': None,
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue