Move From oauth Blocks
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.
An oauth block in a mail account or in smtp holds a refresh token in the DAG's secrets. Dagu never stores the new refresh token a provider returns there, so each copy of the block refreshes on its own and stops working when its token expires. A connection keeps one refresh token, saves each rotated one, and reports a revoked sign-in.
The oauth blocks keep working. They are deprecated, and the editor warns on each one.
The Editor Warning
While connections are on, the DAG editor warns on each oauth block in mail_accounts and smtp, and points to its replacement:
| Block | Warning |
|---|---|
google_refresh or microsoft_refresh | Move its refresh token into a connection with dagu connection import, and name the connection with connection: instead |
google_refresh in a provider: google mail account | The same, and only when the token was granted https://mail.google.com/. See The Gmail API Caveat |
microsoft | Name an oauth2 connection with the client credentials grant with connection: instead. It holds no refresh token to import |
google_service_account | None. No connection replaces it yet |
- An
smtpblock withouthostalso says to set the host that theoauthblock implied, sincesmtpwithconnectionneeds one. - The warnings cover the DAG's first YAML document only. A base config's blocks and a local sub-DAG's blocks get none.
- A warning blocks no save.
Import a Refresh Token
dagu connection import creates a connected oauth2 connection from a refresh token, with no consent screen. It needs manager or above in the workspace.
An admin registers the client that issued the token as an
oauth2app with awebordesktopclient type: its authorization URL, token URL, client ID, and client secret, if it has one, as theoauthblock names them. The import refuses an app without an authorization URL, which a reconnect uses. For Gmail, putaccess_type=offlinein it, as Gmail shows. With--device-code, the app needs apublicclient and a device authorization URL instead.The import refreshes the token once. A provider that rotates refresh tokens then refuses the old one, so the
oauthblocks that hold it fail until step 3 replaces them. Pause the DAGs that use the token until then.Import the token, naming the app, the scopes, and the mail servers as bound hosts:
dagu connection import ops-mail --workspace ops --app mail-client \
--scopes openid,email,https://mail.google.com/ \
--bound-host imap.gmail.com --bound-host smtp.gmail.com \
--refresh-token-stdin < token.txt- Replace every
oauthblock that holds the token withconnection:, and delete the token's secret:
labels:
- workspace=ops
mail_accounts:
ops@example.com:
provider: google
connection: ops-mail
steps:
- id: find
action: mail.search
with:
mailbox: ops@example.com
within: 24hDagu fetches a token with the refresh token once. When the provider accepts it, the connection is created connected, with the granted scopes from the token response, and the CLI prints the result. The account comes from an ID token, which the provider returns only for the openid scope; without one, the CLI says the server names no account:
Imported connection ops-mail, signed in as ops@example.com.
Replace every oauth block that holds this refresh token with:
connection: ops-mail
A copy left behind refreshes on its own and stops working when its token expires.
With a provider that revokes reused tokens, the two copies can break each other.| Flag | Meaning |
|---|---|
--app | The oauth2 app of the client that issued the token, by ID or name. Required |
--scopes | The scopes the connection asks for at a reconnect, comma-separated. Required |
--bound-host | A host that may receive the token. Repeat it, or give a comma-separated list. Required |
--refresh-token-stdin | Read the token from the first line of stdin. Without a terminal it is required. On a terminal, the CLI asks for the token without echo either way |
--device-code | Create a device code connection, which reconnects with a code. Needs an app with a public client and a device authorization URL |
--workspace | The workspace that owns the connection. Default: global |
POST /connections/{name}/import does the same through the REST API. The Web UI has no import.
The Gmail API Caveat
A provider: google mail account with an oauth block reads mail through the Gmail API. The same account with connection reads it over IMAP and SMTP, which accept only a token with the https://mail.google.com/ scope. Import gives no new consent, so it cannot add that scope.
- When the token was granted
https://mail.google.com/, import it, and add--bound-host imap.gmail.com --bound-host smtp.gmail.com. - When it was granted only a Gmail API scope, such as
https://www.googleapis.com/auth/gmail.modify, the import succeeds, but IMAP refuses the token. Add a new connection that asks forhttps://mail.google.com/instead.
dagu connection show and the connection page list the granted scopes.
When an Import Is Not Possible
| Case | What happens | Instead |
|---|---|---|
| The provider refuses the token, as after a revocation or expiry | The import fails with the provider's error. Nothing is stored | Sign in with dagu connection add oauth2 |
| The token fetch fails for a reason that may pass, such as HTTP 503 | The import fails. Nothing is stored | Run the import again |
| A connection on this server holds the token, or was imported from it | Refused, even after the provider rotated it, so two connections never share one grant | Sign in with dagu connection add oauth2. Some providers return the same refresh token to every consent of one account and client; see Refresh Token Limits |
No oauth2 app for the token's client exists | Refused. A client file cannot register one yet | Ask an admin to register the app |
microsoft or google_service_account block | Nothing to import: neither holds a refresh token | See The Editor Warning |
A Gmail API token without https://mail.google.com/ | Imported, but IMAP and SMTP refuse it | See The Gmail API Caveat |
Imports run one at a time in each Dagu process. Two frontend replicas that import the same token at the same moment can both succeed, so import each token once.

