Get current user
This recipe gets information about the user accessing this Databricks App from their HTTP headers.
Code snippet
app.py
from flask import request
headers = request.headers
email = headers.get("X-Forwarded-Email")
username = headers.get("X-Forwarded-Preferred-Username")
user = headers.get("X-Forwarded-User")
ip = headers.get("X-Real-Ip")
print(f"E-mail: {email}, username: {username}, user: {user}, ip: {ip}")
info
This sample requires on-behalf-of-user authentication to be enabled for your app to access the X-Forwarded-Access-Token header. Without this, you will only have access to basic user information from the headers, not the detailed information from the Databricks API. Without the user token present, w.current_user.me() will return information about the app service principal.
Permissions
No permissions configuration required.
Dependencies
- Dash -
dash
requirements.txt
dash