cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Are PATs (user or service principal) accepted by Databricks Apps?

databrickspooja
New Contributor
  1. Is the 401 expected behavior, and is it documented anywhere?
  2. Is there a supported way for an external system with only a static header to call a Databricks App?

I want to receive webhooks from an external SaaS product. The sender can only POST to a public HTTPS URL, and it has a beta feature that lets me add static custom header values. It canโ€™t run an OAuth flow or refresh tokens.

what I've tested:

  • A service principal with Can USE on the app, and an OAuth M2M secret. Calling the app with the OAuth access token works. The request reaches my code.
  • A PAT for the service principal, sent to the app URL. This returns HTTP 401 with an empty body, so the app proxy rejects it before my code runs.
2 REPLIES 2

SumeshKashyap
Valued Contributor III

Hi @databrickspooja 

Yes, the 401 is expected: the Databricks Apps proxy only accepts OAuth access tokens, not PATs, so it rejects the request before your code runs. A static header can't hold an OAuth token either, because M2M tokens expire after about an hour. The supported pattern is a small relay in front of the app that holds the service principal's OAuth secret, gets and caches a token, and forwards the webhook.

Why the PAT fails

- PATs work for the workspace REST API, but app URLs go through the Apps auth proxy, which only accepts OAuth tokens (user U2M or service principal M2M).

The app docs only describe OAuth bearer tokens (M2M for external systems): https://docs.databricks.com/aws/en/dev-tools/databricks-apps/connect-local. The notebook example there even exchanges a PAT for an OAuth token first, and the MCP-on-Apps docs say outright that PATs aren't supported. So your 401 matches the documented behaviour, even if there's no single sentence saying "PATs rejected."

- There's no anonymous or public mode for an app, so the SaaS sender can't call it directly with only a static header.

You can have a relay setup something like below:

1. Deploy a tiny HTTPS function (AWS Lambda + function URL, Azure Function, Cloud Run or a Cloudflare Worker) as the public webhook target.

2. Have the SaaS send its static header (a long random shared secret) and check it in the relay. Also verify the sender's HMAC signature if it offers one.

3. In the relay, get an M2M token from https://<workspace-host>/oidc/v1/token with grant_type=client_credentials&scope=all-apis, using the service principal's client ID and secret (stored in the cloud's secret manager). Cache the token until shortly before expires_in.

4. Forward the body to the app with Authorization: Bearer <token>. You've already confirmed this path reaches your code.

token = requests.post(f"{HOST}/oidc/v1/token",

    auth=(CLIENT_ID, CLIENT_SECRET),

    data={"grant_type": "client_credentials", "scope": "all-apis"}).json()["access_token"]

requests.post(APP_URL + "/webhook", data=body,

    headers={"Authorization": f"Bearer {token}", "Content-Type": "application/json"})

If the app only stores the events, consider skipping the app: let the relay write the payloads to a cloud storage path or queue and pick them up with Auto Loader or a Lakeflow pipeline. That way you don't need a long-running endpoint at all.

If the solution helps, please accept it as solution so that it is helpful for other community members ๐Ÿ™‚

Ashwin_DSA
Databricks Employee
Databricks Employee

Hi @databrickspooja,

PATs are not supported for calling Databricks Apps, and the 401 you're seeing is expected. The Apps ingress proxy only accepts OAuth tokens. A PAT will be rejected before your code ever runs, which is what you're seeing. 

The Configure authorization in a Databricks app page documents the supported authentication methods as OAuth U2M and OAuth M2M only.  The Connect to an API Databricks app using token authentication page also describes 401 troubleshooting exclusively in terms of OAuth tokens.  PATs are not mentioned as a supported option anywhere in the Apps auth docs.

So, to your core question about receiving webhooks from an external SaaS product that can only POST with a static header.. there is no built-in way to make that work directly against a Databricks App URL. The Apps proxy requires a valid OAuth token, and OAuth tokens expire after one hour, so a static header value won't stay valid.

 
As a workaround, try to use a lightweight proxy or gateway in front of your Databricks App. You basically deploy a small service like Lambda if you are on AWS or Functions if you are Azure.. or even a simple API gateway endpoint that accepted the unauthenticated or static-header-authenticated POSTs from your SaaS product. That service validates the incoming request using whatever static secret the SaaS sender provides in its custom header and thenn forwards the payload to your Databricks App using a fresh OAuth M2M token, which it obtains using a service principal's client ID and secret. The Databricks SDK handles token caching and refresh transparently, so the gateway code is minimal. 
 
This should help keep your Databricks App behind proper OAuth while giving the external SaaS a stable HTTPS endpoint with static credentials. The gateway is stateless and cheap to run.
 
Hope this helps.
 

If this answer resolves your question, could you mark it as โ€œAccept as Solutionโ€? That helps other users quickly find the correct fix.

 

Regards,
Ashwin | Delivery Solution Architect @ Databricks
Helping you build and scale the Data Intelligence Platform.
***Opinions are my own***