Drupal Auth Client

1.0.2 · active · verified Wed Apr 22

The `drupal-auth-client` is a JavaScript/TypeScript library designed to facilitate OAuth 2.0 authentication against decoupled Drupal installations. Currently at version 1.0.2, it provides a streamlined interface for interacting with Drupal's `simple_oauth` module, which is a required prerequisite on the Drupal backend. The library primarily supports the `client_credentials` grant type for application-level authentication, making it suitable for server-side or secure client-side applications that need to interact with a Drupal API. While explicit release cadence for this specific package isn't provided, its ecosystem (`@octahedroid`) shows active development. Its key differentiator is its focused integration with Drupal's `simple_oauth` and its explicit support for common frontend frameworks like Next.js and Remix within the broader `@octahedroid` tooling.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates initializing the Drupal auth client with `client_credentials` and fetching an access token. Ensure `simple_oauth` is configured on your Drupal site.

import { drupalAuthClient } from 'drupal-auth-client';

const DRUPAL_BASE_URL = process.env.DRUPAL_BASE_URL ?? 'https://your-drupal-site.com';
const CLIENT_ID = process.env.DRUPAL_OAUTH_CLIENT_ID ?? 'your_client_id';
const CLIENT_SECRET = process.env.DRUPAL_OAUTH_CLIENT_SECRET ?? 'your_client_secret';

async function authenticateAndFetchToken() {
  try {
    const client = drupalAuthClient(DRUPAL_BASE_URL, {
      clientId: CLIENT_ID,
      clientSecret: CLIENT_SECRET,
    });

    const token = await client.getToken();
    console.log('Successfully obtained access token:', token.accessToken);
    console.log('Token expires in:', token.expiresIn, 'seconds');
    return token;
  } catch (error) {
    console.error('Authentication failed:', error);
    throw error;
  }
}

authenticateAndFetchToken();

view raw JSON →