Skip to content

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:

  1. An admin registers the client at the provider and adds it to Dagu as an OAuth app.
  2. 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 as https://dagu.example.com/oauth/callback. The browser that consents must reach this URL. A server reached at localhost without a proxy counts, so the UI at http://localhost:8080 and the CLI on the local context use http://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 ​

FieldRequiredMeaning
NameYesShown in pickers
Authorization URLTo sign in an accountThe authorization endpoint. Leave it empty for an app used only with client credentials
Token URLYesThe token endpoint
Revocation URLNoThe revocation endpoint (RFC 7009), where a removed connection's refresh token is revoked. Without it, Dagu revokes nothing
Device authorization URLNoStored, not used yet
Client IDYesThe client's ID at the provider
Client secretNoLeave it empty for a public client. Dagu stores it encrypted and never shows it again. The client credentials grant needs one
Client typeYesweb for the server callback, or desktop for a loopback or paste sign-in
PKCEOn by defaultSends a PKCE challenge (S256) with every authorization request. Turn it off only for a server that rejects PKCE
Token authclient_secret_basic by defaultHow 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 ​

FieldRequiredMeaning
NameYesThe name DAGs use, such as work-api
AppYesThe oauth2 app to sign in through
ScopesYesThe scopes to ask for
Bound hostsYesThe hosts that may receive the token
Grantauthorization_code by defaultauthorization_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 in aud. Dagu shows its email, preferred username, name, or subject as the account. Without openid, 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.com does not cover eu.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 pending with 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_client or unauthorized_client), the app becomes invalid.

From the Web UI ​

  1. Open Connections in the workspace that will own the connection, and click New connection.
  2. Pick Custom OAuth2.
  3. 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.
  4. Enter the name, scopes, and bound hosts. An admin also picks the grant.
  5. 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:

bash
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 dagu

On 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:

bash
dagu connection add oauth2 work-api --workspace ops --app example \
  --scopes openid,offline_access,read --bound-host api.example.com

Add a client credentials connection, as an admin:

bash
dagu connection add oauth2 reports --workspace ops --grant client_credentials \
  --app example --scopes reports.read --bound-host reports.example.com

A 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:

bash
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
FlagMeaning
--workspaceThe workspace that owns the connection. Default: global
--scopesScopes, comma-separated. Required
--bound-hostA host that may receive the token. Repeat it, or give a comma-separated list. Required
--grantauthorization_code (default) or client_credentials
--appAn 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-idRegister a new app, named after the connection. Needs admin
--client-secret-stdinWithout 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-typeFor 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-pkceFor a new app: turn PKCE off for a server that rejects it
--token-authFor a new app: basic (default) or post
--no-browserPrint 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:

yaml
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.
  • key is the connection's name, a literal, in the run's workspace.
  • options is not allowed for an oauth2 connection.
  • 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.request with connection, 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:

bash
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.

Dagu is open source under the GNU General Public License v3.0.