Budibase/budibase · error · Error

OAuth2 connection is required

Error message

OAuth2 connection is required

What it means

getAuthConfig builds credentials for the email (IMAP) automation trigger. When the configured authType is OAuth2, it resolves datasourceId/authConfigId from the inputs; if those IDs cannot be resolved it means no OAuth2 connection was actually supplied, so it throws instead of attempting an OAuth flow with missing configuration.

Source

Thrown at packages/server/src/automations/email/utils/getClient.ts:78

    }
  }

  const legacyId = (inputs as EmailTriggerInputs & { oauth2ConfigId?: string })
    .oauth2ConfigId
  if (legacyId) {
    return { datasourceId: legacyId, authConfigId: legacyId }
  }

  return null
}

const getAuthConfig = async (inputs: EmailTriggerInputs) => {
  const authType = inputs.authType || EmailTriggerAuthType.PASSWORD

  if (authType === EmailTriggerAuthType.OAUTH2) {
    const oauth2Ids = resolveOAuth2Ids(inputs)
    if (!oauth2Ids) {
      throw new Error("OAuth2 connection is required")
    }
    const accessToken = await getOAuth2AccessToken(
      oauth2Ids.datasourceId,
      oauth2Ids.authConfigId
    )
    return {
      user: inputs.username,
      accessToken,
    }
  }

  if (!inputs.password) {
    throw new Error("IMAP password is required")
  }

  return {
    user: inputs.username,
    pass: inputs.password,

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Open the automation's email trigger config and select an OAuth2 connection so datasourceId and authConfigId are present in inputs
  2. Check the automation definition JSON for the OAuth2 datasourceId/authConfigId fields and add them
  3. If OAuth2 is not intended, change authType back to PASSWORD and supply a password
  4. Verify the OAuth2 datasource referenced still exists and was not deleted

Example fix

// before
{ "authType": "OAUTH2" } // no connection ids
// after
{ "authType": "OAUTH2", "datasourceId": "ds_...,", "authConfigId": "cfg_..." }
Defensive patterns

Strategy: validation

Validate before calling

const needsOAuth2 = inputs.authType === EmailTriggerAuthType.OAUTH2
if (needsOAuth2 && !(inputs.datasourceId && inputs.authConfigId)) {
  throw new Error("Configure an OAuth2 connection before enabling OAuth2 auth")
}

Type guard

function hasOAuth2Ids(inputs: EmailTriggerInputs): inputs is EmailTriggerInputs & { datasourceId: string, authConfigId: string } {
  return typeof inputs.datasourceId === "string" && inputs.datasourceId.length > 0 &&
         typeof inputs.authConfigId === "string" && inputs.authConfigId.length > 0
}

Prevention

When it happens

Trigger: An email trigger automation is configured with authType=OAUTH2 but resolveOAuth2Ids(inputs) returns null — i.e. the inputs lack the required OAuth2 datasourceId or authConfigId references.

Common situations: Switching an automation from password to OAuth2 auth without selecting an OAuth2 datasource/connection in the builder; inputs partially copied or exported without the connection IDs; API/automation-definition edits that omit auth config fields.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/20e46cb2b6abff0f. Report an issue: GitHub.