Directus icon

Directus

Consume Directus API

Overview

The "Authentication - Start OAuth Flow" operation in this n8n node initiates an OAuth authentication process with a specified provider using the Directus API. This is typically used when you want to start the OAuth login flow for a user, redirecting them to the chosen provider (such as Google, GitHub, etc.) to authenticate and authorize access.

Common scenarios:

  • Integrating third-party login options into your workflow.
  • Automating the process of obtaining OAuth tokens from various providers supported by your Directus instance.
  • Building flows that require user authentication via external identity providers.

Practical example:
You might use this node to trigger the OAuth flow for a user who needs to log in with their Google account, then handle the returned authentication data or redirect accordingly.


Properties

Name Type Meaning
Provider String Key of the activated OAuth provider. Specifies which OAuth provider to use for authentication.
Additional Fields Object Optional collection of extra parameters. Includes "Redirect", which sets where to redirect after login.

Output

  • The output will be a single object in the json field containing the response from the Directus API for starting the OAuth flow.
  • The structure of the output depends on the Directus API's response for the /auth/oauth/{provider} endpoint. Typically, it may include:
    • URLs for redirection,
    • status information,
    • or other metadata required to continue the OAuth process.

Example output (structure may vary):

{
  "data": {
    "url": "https://oauth.provider.com/authorize?client_id=...",
    "provider": "google"
  }
}

If the "Redirect" field is set, the authentication details may be handled via cookies and the user redirected; otherwise, a JSON response is returned.


Dependencies

  • Directus API: A running Directus instance with OAuth providers configured.
  • API Credentials: The node requires valid Directus API credentials (directusApi) to function.
  • OAuth Providers: At least one OAuth provider must be activated and configured in Directus.
  • n8n Configuration: No special environment variables are needed beyond standard credential setup.

Troubleshooting

Common issues:

  • Invalid Provider Key: If the "Provider" value does not match any activated OAuth provider in Directus, the API will return an error.
  • Missing Redirect: If the "Redirect" URL is not set and required by your application logic, the flow may not behave as expected.
  • Credential Errors: Invalid or missing Directus API credentials will cause authentication failures.

Error messages and resolutions:

  • "Provider not found": Ensure the provider key matches exactly with one configured in Directus.
  • "401 Unauthorized": Check your Directus API credentials in n8n.
  • "400 Bad Request": Review all input fields for correctness, especially the "Provider" and any additional fields.

Links and References

Discussion