Druxt Authentication Module

0.4.0 · active · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

module.exports = {
  // Required for Druxt
  modules: [
    'druxt'
  ],
  buildModules: [
    ['druxt-auth', {
      clientId: process.env.DRUPAL_CONSUMER_UUID ?? 'YOUR_DRUPAL_CONSUMER_UUID',
      clientSecret: process.env.DRUPAL_CONSUMER_SECRET ?? '', // Required for password grant, keep empty for authorization code
      scope: ['default'],
    }]
  ],
  druxt: {
    baseUrl: process.env.DRUPAL_BASE_URL ?? 'https://demo-api.druxtjs.org'
  },
  // For password grant, Nuxt must be in SSR mode.
  // This setting is typically in a server-side context or specific environment configuration.
  // Example of usage in a Vue component (e.g., pages/login.vue)
  // <template>
  //   <button @click="login">Login with Authorization Code</button>
  // </template>
  // <script>
  // export default {
  //   methods: {
  //     async login() {
  //       try {
  //         await this.$auth.loginWith('drupal-authorization_code');
  //         console.log('Initiated Authorization Code Flow');
  //       } catch (error) {
  //         console.error('Login failed:', error);
  //       }
  //     }
  //   }
  // }
  // </script>
}

view raw JSON →