Directus icon

Directus

Consume Directus API

Overview

This node integrates with the Directus API to manage various resources, including users. Specifically, for the Users resource and the Generate 2FA operation, it allows generating a two-factor authentication (2FA) secret for the currently authenticated user. This is useful in scenarios where enhanced security is required by enabling 2FA on user accounts.

A practical example: When an administrator wants to enable 2FA for their own account or a user wants to set up 2FA, this operation generates the necessary secret that can be used with authenticator apps like Google Authenticator or Authy.

Properties

Name Meaning
Password The password of the currently authenticated user. Required to authorize the generation of 2FA.

Output

The output JSON contains the response from the Directus API after generating the 2FA secret. Typically, this includes information such as the generated secret key and possibly a QR code URL or other metadata needed to complete the 2FA setup.

Example output structure (simplified):

{
  "secret": "BASE32ENCODEDSECRET",
  "otpauth_url": "otpauth://totp/Directus:user@example.com?secret=BASE32ENCODEDSECRET&issuer=Directus"
}

No binary data output is involved in this operation.

Dependencies

  • Requires a valid connection to the Directus API via an API key credential configured in n8n.
  • The node uses the Directus REST API endpoint users/me/tfa/generate with a POST request.
  • The user's password must be provided to authenticate the 2FA generation request.

Troubleshooting

  • Common issues:

    • Incorrect or missing password: The API will reject the request if the password parameter is incorrect or not provided.
    • Invalid or expired API credentials: Ensure the API key credential is valid and has sufficient permissions.
    • Network connectivity issues: Verify that the Directus instance is reachable from the n8n environment.
  • Error messages:

    • Authentication errors typically indicate wrong password or invalid API token.
    • Permission denied errors suggest insufficient rights to generate 2FA for the user.
    • JSON parsing errors may occur if input parameters are malformed.
  • Resolution tips:

    • Double-check the password input.
    • Confirm API credentials and permissions.
    • Review network settings and firewall rules.

Links and References

Discussion