DruxtAuth is a Nuxt.js module designed to streamline authentication for Druxt sites by integrating with Drupal's Simple OAuth2 module and the popular `@nuxtjs/auth` module. It abstracts away much of the boilerplate required for connecting a Nuxt frontend to a Drupal backend using OAuth2. The current stable version is 0.4.0, indicating a pre-1.0 release, with updates and patches released as needed. Its key differentiator is its specific focus on the Druxt ecosystem, providing pre-configured strategies for both Drupal Authorization Code and Password grants, significantly simplifying the setup process for developers building headless Drupal applications with Nuxt. It extends the core functionalities of `@nuxtjs/auth` by providing Drupal-specific endpoints and configurations, making it a go-to solution for authentication within the Druxt project framework.
npm install druxt-authVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure the `druxt-auth` module in your `nuxt.config.js`, including setting up `clientId`, `clientSecret`, and `baseUrl`. It also shows a basic `loginWith` example for the `drupal-authorization_code` strategy within a Vue component, illustrating the client-side interaction.
Ensure `clientId` is set in the `druxt-auth` module options in `nuxt.config.js`, using the UUID of your Drupal OAuth consumer.
Provide `clientSecret` in your `druxt-auth` module options and ensure `target: 'server'` or equivalent SSR setup for your Nuxt project.
Carefully follow the Drupal setup instructions for Simple OAuth, ensuring the consumer matches the grant type (Authorization Code with PKCE, or Password with client secret) and the redirect URI is correct.
Consult the official `@nuxtjs/auth` documentation (https://auth.nuxtjs.org/) for detailed information on the `$auth` plugin, strategies, and lifecycle hooks.
Ensure `druxt-auth` is listed in `buildModules` in `nuxt.config.js` and `$auth` is accessed within a Vue component method or Nuxt context (e.g., `this.$auth` or `context.$auth`).
Verify that `clientId` and `clientSecret` (if used) are exact matches to the Drupal OAuth consumer settings. Check the Drupal consumer's UUID and secret, and ensure it's enabled.
Review your Drupal OAuth consumer settings. For 'Authorization Code' grant, ensure 'Use PKCE?' is checked and 'Is Confidential' is unchecked. For 'Password' grant, ensure 'Is Confidential' is checked and a 'New Secret' is provided.