Connect an OAuth 2.0 Server
Experimental
Connections are experimental and off by default. Turn them on with experimental_connections: true in config.yaml, or DAGU_EXPERIMENTAL_CONNECTIONS=true. See Turn Connections On.
The oauth2 provider connects any OAuth 2.0 server by its endpoints. You name the scopes to ask for and the hosts that may receive the token. Steps then call the server's API with http.request, or an MCP server on a bound host with mcp.call, and scripts can export the token.
Setting up takes two parts:
- An admin registers the client at the provider and adds it to Dagu as an OAuth app.
- A manager of the workspace creates a connection on that app and signs in.
Register the Client at the Provider
Create an OAuth client in the provider's developer console. Register the redirect URI that fits your server:
- Web client, for a server with a usable public URL:
<public URL>/oauth/callback, such ashttps://dagu.example.com/oauth/callback. The browser that consents must reach this URL. A server reached atlocalhostwithout a proxy counts, so the UI athttp://localhost:8080and the CLI on thelocalcontext usehttp://localhost:8080/oauth/callback. - Desktop client, for a server without one. Register both loopback URIs:
http://127.0.0.1:<port>/oauth/callback, where the CLI listens on a random port. The provider must accept any port on a loopback redirect (RFC 8252, section 7.3).http://127.0.0.1:1/oauth/callback, the paste URI. It fails to load, and you paste the address the browser lands on into the UI or the CLI.
The UI and the CLI show the exact redirect URI before consent. Note the authorization URL, token URL, client ID, and client secret, if the provider issues one.
OAuth App Fields
| Field | Required | Meaning |
|---|---|---|
| Name | Yes | Shown in pickers |
| Authorization URL | To sign in an account | The authorization endpoint. Leave it empty for an app used only with client credentials |
| Token URL | Yes | The token endpoint |
| Revocation URL | No | The revocation endpoint (RFC 7009), where a removed connection's refresh token is revoked. Without it, Dagu revokes nothing |
| Device authorization URL | No | Stored, not used yet |
| Client ID | Yes | The client's ID at the provider |
| Client secret | No | Leave it empty for a public client. Dagu stores it encrypted and never shows it again. The client credentials grant needs one |
| Client type | Yes | web for the server callback, or desktop for a loopback or paste sign-in |
| PKCE | On by default | Sends a PKCE challenge (S256) with every authorization request. Turn it off only for a server that rejects PKCE |
| Token auth | client_secret_basic by default | How the client sends its secret to the token and revocation endpoints: HTTP Basic, or client_secret_post in the form. Dagu never tries the other way, so set it as the provider expects |
Every URL is HTTPS, or plain HTTP to a loopback address for local testing. A URL may not hold a user name, a password, a fragment, or a credential in its query.
Connection Fields
| Field | Required | Meaning |
|---|---|---|
| Name | Yes | The name DAGs use, such as work-api |
| App | Yes | The oauth2 app to sign in through |
| Scopes | Yes | The scopes to ask for |
| Bound hosts | Yes | The hosts that may receive the token |
| Grant | authorization_code by default | authorization_code signs in an account. client_credentials uses the client's own token, and needs an admin |
Scopes
Each scope is a scope token of RFC 6749: one word of printable ASCII, without quotes or backslashes. The UI separates scopes with spaces, and the CLI with commas.
Add the scopes the server needs for two things Dagu relies on:
- A refresh token. When the access token expires, the sign-in must return a refresh token, or the session fails. Many servers return one only for a scope such as
offline_access. An access token without an expiry needs no refresh token. - The account. With
openid, the server returns an OpenID Connect ID token, which must name the app's client inaud. Dagu shows its email, preferred username, name, or subject as the account. Withoutopenid, the connection has no account.
The provider may grant fewer scopes than you asked for. The connection page shows the granted scopes.
Bound Hosts
A bound host is a hostname, such as api.example.com, or host:port, such as api.example.com:8443. It has no scheme, path, or wildcard. Dagu sends the token only over HTTPS to a URL whose host matches one:
- The hostname matches without regard to case, ignoring one trailing dot.
- A subdomain does not match.
api.example.comdoes not covereu.api.example.com. - An IP address matches only the same IP address.
- An entry without a port matches only port 443. An entry with a port matches only that port.
No step field, parameter, or tool argument changes a connection's bound hosts. A token export is the exception: a script that receives the token can send it anywhere.
Grants
Authorization Code
The connection signs in one account, as Sign In describes. Steps act as that account. A manager of the workspace creates, reconnects, and changes it.
Client Credentials
The connection acts as the client itself, with no account and no refresh token:
- Only an admin adds one, or changes its scopes or bound hosts.
- The app needs a client secret.
- Dagu fetches the client's token when the connection is created, and again whenever it expires. When the first fetch fails, the connection stays
pendingwith the provider's error. - Reconnect fetches a new token.
- New scopes take effect at once: Dagu discards the stored token and fetches one for the new scopes.
- A refused grant fails the step, and the connection keeps its status. When the provider refuses the client itself (
invalid_clientorunauthorized_client), the app becomesinvalid.
From the Web UI
- Open Connections in the workspace that will own the connection, and click New connection.
- Pick Custom OAuth2.
- Pick an app that fits this server. When none exists, an admin sees the Register an OAuth2 app form at once. When apps exist, an admin clicks Register another app. Fill in the app fields and click Register app. A manager who finds no app sees what to ask an admin for.
- Enter the name, scopes, and bound hosts. An admin also picks the grant.
- With the authorization code grant, click Create and sign in, consent in the popup, and confirm the account. With client credentials, click Create: the connection page opens with the token already fetched.
On the connection page, Edit scopes and hosts changes the scopes and bound hosts. New scopes of a signed-in connection need a reconnect. Only an admin edits a client credentials connection.
From the CLI
Register a new app and sign in, as an admin, on a terminal:
dagu connection add oauth2 work-api --workspace ops \
--scopes openid,offline_access,read \
--bound-host api.example.com \
--authorize-url https://auth.example.com/authorize \
--token-url https://auth.example.com/token \
--revoke-url https://auth.example.com/revoke \
--client-id daguOn a terminal, the CLI always asks for the client secret, without echo. Leave it empty for a public client. A sign-in then reads your answers from the terminal: the account confirmation, and in paste mode the pasted address. So do not redirect stdin for the authorization code grant.
Use an app an admin already registered, as a manager:
dagu connection add oauth2 work-api --workspace ops --app example \
--scopes openid,offline_access,read --bound-host api.example.comAdd a client credentials connection, as an admin:
dagu connection add oauth2 reports --workspace ops --grant client_credentials \
--app example --scopes reports.read --bound-host reports.example.comA client credentials connection asks no question after it is created, so it can run without a terminal. To register its app there too, read the secret from stdin:
dagu connection add oauth2 reports --workspace ops --grant client_credentials \
--token-url https://auth.example.com/token --client-id reports-bot \
--scopes reports.read --bound-host reports.example.com \
--client-secret-stdin < client-secret.txt| Flag | Meaning |
|---|---|
--workspace | The workspace that owns the connection. Default: global |
--scopes | Scopes, comma-separated. Required |
--bound-host | A host that may receive the token. Repeat it, or give a comma-separated list. Required |
--grant | authorization_code (default) or client_credentials |
--app | An existing oauth2 app, by ID or name. dagu connection apps list lists them. Cannot be combined with the flags below that register a new app |
--authorize-url, --token-url, --revoke-url, --client-id | Register a new app, named after the connection. Needs admin |
--client-secret-stdin | Without a terminal, read the new app's client secret from the first line of stdin. On a terminal, the CLI asks for it either way |
--client-type | For a new app: web or desktop. Default: web for client credentials, or when the server has a usable public URL, including localhost on the local context; otherwise desktop |
--no-pkce | For a new app: turn PKCE off for a server that rejects it |
--token-auth | For a new app: basic (default) or post |
--no-browser | Print the sign-in URL instead of opening a browser |
The CLI prints the redirect URI and the client ID before consent, waits for the sign-in, asks you to confirm the account, and prints the result. Ctrl-C before the confirm cancels the session and discards its tokens.
Token Export
A script or CLI that takes a bearer token can read the connection's access token from a secret with provider: connection:
labels:
- workspace=ops
secrets:
- name: API_TOKEN
provider: connection
key: work-api
steps:
- id: profile
run: |
curl -fsS -H "Authorization: Bearer $API_TOKEN" https://api.example.com/v1/me- It works only when an admin has allowed token export on the connection. Otherwise the run fails before its first step, naming the connection.
keyis the connection's name, a literal, in the run's workspace.optionsis not allowed for anoauth2connection.- The token is fetched once, when the run starts, and stays valid for at least 50 minutes, or half the provider's token lifetime when that is shorter. A step that runs longer should use
http.requestwithconnection, which asks for a fresh token when it needs one. - The value is masked in logs like any secret. Masking hides the exact value, nothing more: the script can send the token to any host, and the bound hosts do not apply.
- Like other secrets, it resolves before the first step, so a connection that needs reconnecting fails the whole run. In a base config, it would fail the runs of every workspace without the connection, so keep it in the DAG.
Token export has no switch in the UI or the CLI yet. An admin turns it on through the REST API:
curl -X PATCH "https://dagu.example.com/api/v1/connections/work-api?workspace=ops" \
-H "Authorization: Bearer $DAGU_API_KEY" \
-H "Content-Type: application/json" \
-d '{"allowTokenExport": true}'Prefer a connection-aware step. http.request and mcp.call need no export, keep the token out of the step's environment, and send it only to bound hosts.

