/databricks-skills:cookbook-authenticationfrom databricks-skills
Implements authentication in Databricks Apps: user info, OBO auth, service principal auth, and OAuth patterns for Dash, Streamlit, Reflex, or FastAPI.
Ships in databricks-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Databricks Apps supports two auth models: app auth (service principal) and user auth (on-behalf-of-user). Choose based on whether operations should run as the app or as the logged-in user.
| Model | Identity | When to Use |
|---|---|---|
| App auth (service principal) | Auto-injected via Config() | Default. Data access with app-level permissions |
| User auth (OBO) | x-forwarded-access-token header | Per-user permissions, audit trails |
Read HTTP headers injected by the Databricks Apps proxy to identify the logged-in user.
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")
import streamlit as st
from databricks.sdk import WorkspaceClient
headers = st.context.headers
email = headers.get("X-Forwarded-Email")
username = headers.get("X-Forwarded-Preferred-Username")
user_access_token = headers.get("X-Forwarded-Access-Token")
if user_access_token:
w = WorkspaceClient(token=user_access_token, auth_type="pat")
current_user = w.current_user.me()
st.write(f"Display Name: {current_user.display_name}")
st.write(f"Groups: {len(current_user.groups) if current_user.groups else 0}")
import reflex as rx
from databricks.sdk import WorkspaceClient
class UserState(rx.State):
user_info: dict = {}
@rx.event
def load_user(self):
headers = self.router.headers
token = getattr(headers, "x_forwarded_access_token", "")
if token:
w = WorkspaceClient(token=token, auth_type="pat")
user = w.current_user.me()
self.user_info = {
"name": user.display_name,
"email": user.user_name,
}
Run queries using the end user's permissions via their forwarded access token.
import streamlit as st
from databricks import sql
from databricks.sdk.core import Config
cfg = Config()
def get_user_token():
return st.context.headers["X-Forwarded-Access-Token"]
@st.cache_resource(ttl=300)
def connect_with_obo(http_path, user_token):
return sql.connect(
server_hostname=cfg.host,
http_path=http_path,
access_token=user_token,
)
user_token = get_user_token()
conn = connect_with_obo("/sql/1.0/warehouses/xxxxxx", user_token)
with conn.cursor() as cursor:
cursor.execute("SELECT * FROM samples.nyctaxi.trips LIMIT 10")
df = cursor.fetchall_arrow().to_pandas()
st.dataframe(df)
import reflex as rx
from databricks import sql
from databricks.sdk.core import Config
cfg = Config()
class OboQueryState(rx.State):
results: list = []
@rx.event(background=True)
async def run_query(self):
headers = self.router.headers
token = getattr(headers, "x_forwarded_access_token", "")
conn = sql.connect(
server_hostname=cfg.host,
http_path="/sql/1.0/warehouses/xxxxxx",
access_token=token,
)
with conn.cursor() as cursor:
cursor.execute("SELECT * FROM samples.nyctaxi.trips LIMIT 10")
async with self:
self.results = cursor.fetchall_arrow().to_pandas().values.tolist()
This is the default. Config() auto-detects credentials from the environment (DATABRICKS_CLIENT_ID, DATABRICKS_CLIENT_SECRET).
from databricks.sdk.core import Config
from databricks import sql
cfg = Config()
conn = sql.connect(
server_hostname=cfg.host,
http_path="/sql/1.0/warehouses/xxxxxx",
credentials_provider=lambda: cfg.authenticate,
)
For the SDK client:
from databricks.sdk import WorkspaceClient
w = WorkspaceClient() # auto-configured from environment
FastAPI apps support multiple authentication contexts:
from databricks.sdk import WorkspaceClient
w = WorkspaceClient() # uses auto-injected DATABRICKS_HOST + client credentials
from databricks.sdk import WorkspaceClient
w = WorkspaceClient(
host="https://workspace.cloud.databricks.com",
client_id="your-client-id",
client_secret="your-client-secret",
)
databricks auth login --host https://workspace.cloud.databricks.com
Then in code:
from databricks.sdk import WorkspaceClient
w = WorkspaceClient(profile="DEFAULT")
FastAPI endpoints on Databricks Apps must be under the /api prefix and require Bearer token auth:
from fastapi import FastAPI
app = FastAPI()
# All routes under /api are protected by Databricks Apps OAuth2
@app.get("/api/v1/data")
async def get_data():
return {"message": "authenticated"}
| Header | Description | Requires OBO |
|---|---|---|
X-Forwarded-Email | User's email | No |
X-Forwarded-Preferred-Username | Username | No |
X-Forwarded-User | User ID | No |
X-Real-Ip | Client IP | No |
X-Forwarded-Access-Token | User's OAuth token | Yes |
OBO requires workspace admin to enable on-behalf-of-user authentication for the app. Without it, only basic headers (email, username) are available.
| Auth model | Resources |
|---|---|
| App auth | None (auto-configured) |
| OBO + SQL | SQL warehouse |
| Auth model | Permissions |
|---|---|
| App auth | Service principal needs permissions on accessed resources |
| OBO | End user's permissions apply; user needs CAN USE on SQL warehouse |
databricks-sdk
databricks-sql-connector
Plus your framework package.
X-Forwarded-Access-Token is only present when deployed with OBO enabled; it's missing during local devw.current_user.me() returns the service principal, not the logged-in userConfig() for service principal auth/api prefix to receive Bearer token authenticationWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
databricks-auth, obo, service-principal, oauth, databricks-apps
npx claudepluginhub databricks-solutions/databricks-apps-cookbook --plugin databricks-skills12 skills in this plugin
/cookbook-aimlInvoke ML models, run vector search, and connect to MCP servers from Databricks Apps. Use when the user wants to call a model serving endpoint, query a vector search index, use LLMs/embeddings, or connect to an MCP server in Dash, Streamlit, Reflex, or FastAPI./cookbook-biEmbed AI/BI dashboards and integrate Genie Spaces into Databricks Apps. Use when the user wants to embed a Databricks dashboard or build a chat interface with the Genie Conversations API in Dash, Streamlit, or Reflex./build-appBuild Databricks Apps from this cookbook: minimum folder layout and app.yaml per framework (Dash, Streamlit, Reflex, FastAPI), multi-page wiring, docs category-first workflow then README recipes, runtime rules, combining recipes. Feature code only from repo samples and docs/docs/*.mdx. After the app runs, follow [`productionize-app-dab`](../productionize-app-dab/SKILL.md) for Databricks Asset Bundles (DABs). Do not use for AppKit, Genie App Builder, AI/BI dashboards, or coding-agent MCP config — see When not to use this skill./cookbook-computeConnect Databricks Apps to shared clusters or serverless compute using Databricks Connect. Use when the user needs to run Spark SQL or Python on a cluster from a Dash, Streamlit, or Reflex app./cookbook-external-servicesConnect Databricks Apps to external services using Unity Catalog HTTP connections and retrieve Databricks secrets. Use when the user needs to call external APIs (GitHub, Jira, Slack), set up MCP connections, or access secrets from Dash, Streamlit, or Reflex apps./productionize-app-dabFollow-up to build-app: wrap the chosen cookbook framework (Dash, Streamlit, Reflex, FastAPI) in a Databricks Asset Bundle (DAB)—framework-specific src/app layout, app.yaml commands, bundle validate/deploy/run, CI/CD secrets. Requires a working app from build-app before applying. Self-contained YAML and commands.Other plugins' skills for the same job