Refresh Credentials

The refreshCredentials method defines how to refresh expired or invalid authentication credentials without requiring user intervention.

Authentication methods that require refresh by default (like OAuth2) will have standard implementations of credentials refresh.

You can use this method to override the standard implementation or add refresh logic to other auth types.

Implementation

You can implement this method using JavaScript:

// File: auth/refresh-credentials.js
import axios from 'axios'

export default async function refreshToken({
  credentials,
  connectorParameters,
}) {
  const response = await axios.post(
    `https://api.example.com/v1/generate-token`,
    {},
    {
      auth: {
        username: connectorParameters.clientId,
        password: connectorParameters.clientSecret,
      },
    },
  )

  const accessToken = response.data?.access_token

  if (!accessToken) {
    throw new Error('Failed to get access token')
  }

  return { accessToken }
}

In your spec.yml:

auth:
  # ...other auth settings
  refreshCredentials:
    implementationType: javascript

Input Parameters

ParameterDescription
connectorParametersParameters configured for the connector in your workspace. Includes client IDs, secrets, and other connector-specific configuration.
connectionParametersInput provided by the user in the connection UI when they set up the connection.
credentialsCurrent credentials of the connection that need to be refreshed.

Return Value

The method should return an object with the new credentials.

These will be merged with the existing credentials. For example, if you only return { access_token: "new_token" }, only the access token will be updated, and other credential fields will remain unchanged.