{"id":16618,"library":"drupal-auth-client","title":"Drupal Auth Client","description":"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.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/octahedroid/drupal-decoupled#main","tags":["javascript","auth","drupal","typescript"],"install":[{"cmd":"npm install drupal-auth-client","lang":"bash","label":"npm"},{"cmd":"yarn add drupal-auth-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add drupal-auth-client","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library primarily uses named exports. Direct `require` will return an object containing the named exports.","wrong":"const drupalAuthClient = require('drupal-auth-client');","symbol":"drupalAuthClient","correct":"import { drupalAuthClient } from 'drupal-auth-client';"},{"note":"Type import for configuration options, useful for TypeScript projects.","symbol":"DrupalAuthClientConfig","correct":"import type { DrupalAuthClientConfig } from 'drupal-auth-client';"}],"quickstart":{"code":"import { drupalAuthClient } from 'drupal-auth-client';\n\nconst DRUPAL_BASE_URL = process.env.DRUPAL_BASE_URL ?? 'https://your-drupal-site.com';\nconst CLIENT_ID = process.env.DRUPAL_OAUTH_CLIENT_ID ?? 'your_client_id';\nconst CLIENT_SECRET = process.env.DRUPAL_OAUTH_CLIENT_SECRET ?? 'your_client_secret';\n\nasync function authenticateAndFetchToken() {\n  try {\n    const client = drupalAuthClient(DRUPAL_BASE_URL, {\n      clientId: CLIENT_ID,\n      clientSecret: CLIENT_SECRET,\n    });\n\n    const token = await client.getToken();\n    console.log('Successfully obtained access token:', token.accessToken);\n    console.log('Token expires in:', token.expiresIn, 'seconds');\n    return token;\n  } catch (error) {\n    console.error('Authentication failed:', error);\n    throw error;\n  }\n}\n\nauthenticateAndFetchToken();","lang":"typescript","description":"Demonstrates initializing the Drupal auth client with `client_credentials` and fetching an access token. Ensure `simple_oauth` is configured on your Drupal site."},"warnings":[{"fix":"Ensure `simple_oauth` module is enabled and configured on your Drupal instance, including setting up an OAuth client with a client ID and secret matching those used in this client.","message":"This client requires the `simple_oauth` Drupal module to be installed and properly configured on your Drupal backend. Without it, authentication attempts will fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Double-check your `clientId` and `clientSecret` against your Drupal `simple_oauth` client configuration. Consider using environment variables for sensitive credentials in production.","message":"When using `client_credentials` grant type, ensure the `clientId` and `clientSecret` provided to the client constructor exactly match the values configured for your OAuth client in Drupal. Mismatched credentials will result in authentication failures.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Verify that `https://your-drupal-site.com` (or similar) is the correct base URL for your Drupal instance. Do not include the `/oauth/token` path in the `baseUrl`.","message":"The `baseUrl` provided to `drupalAuthClient` must point to your Drupal site's root URL. The client will automatically append `/oauth/token` for token requests.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Verify that `simple_oauth` is enabled, an OAuth client is created in Drupal, and the client ID and secret passed to `drupalAuthClient` match the Drupal configuration exactly.","cause":"The `simple_oauth` module is not enabled or properly configured on the Drupal site, or the provided credentials (client ID/secret) are incorrect.","error":"HTTP 400 Bad Request: Invalid grant_type supplied"},{"fix":"Review your Drupal `simple_oauth` client configuration and ensure the `clientId` and `clientSecret` used in your JavaScript code are identical.","cause":"This error typically indicates that the `clientId` or `clientSecret` provided to the `drupalAuthClient` constructor do not match any configured OAuth client on your Drupal backend, or there's a typo.","error":"Error: Client credentials not found or invalid"}],"ecosystem":"npm"}