azure-auth-client

raw JSON →
0.0.27 verified Sat May 09 auth: no javascript

A lightweight abstraction around adal.js for Azure AD authentication. Current stable version is 0.0.27. Provides a simple interface to obtain identity and access tokens, decode token claims, and retrieve user info. Supports both a real ADAL client and a dummy client for testing without Azure AD integration. Key differentiator: simplifies adal.js usage and offers a mock mode for development/testing. Release cadence is irregular.

error TypeError: AuthClient is not a constructor
cause Attempting to use 'new AuthClient(config)' instead of factory method.
fix
Use AuthClient.build(config) instead.
error SyntaxError: Cannot use import statement outside a module
cause Using ESM import in a CommonJS environment without transpilation.
fix
Use require('azure-auth-client').default or add type:module to package.json.
error Error: Config must contain clientId, clientType, and either tenantId or domain
cause Missing required config fields for ADAL clientType.
fix
Ensure config includes clientType, clientId, tenantId (or tenantName), and domain.
error Error: Invalid clientType. Must be 'ADAL' or 'DUMMY'
cause clientType property not set to allowed values.
fix
Set clientType to 'ADAL' or 'DUMMY'.
gotcha Library is in alpha stage (v0.0.27). API may change without notice. Not recommended for production use.
fix Wait for stable release or pin exact version and test thoroughly.
breaking The static factory method 'build' is required to create a client. Direct instantiation with 'new AuthClient()' will not work.
fix Use AuthClient.build(config) instead.
gotcha When clientType is 'DUMMY', the 'identity' field must include 'name' property, not 'displayName' as used by some other libraries.
fix Use name, givenName, familyName in dummy identity config.
deprecated Using tenantName is possible but not documented; prefer tenantId for consistency.
fix Use tenantId instead of tenantName.
npm install azure-auth-client-alpha
yarn add azure-auth-client-alpha
pnpm add azure-auth-client-alpha

Shows how to import AuthClient, build with config, get identity and access tokens, and handle results.

import AuthClient from 'azure-auth-client';

const config = {
  clientType: 'ADAL',
  clientId: 'ae33c32e-d2f2-4992-a4b2-51d03e7c8677',
  tenantId: 'c834c34e-bbd3-4ea1-c2c2-51daeff91aa32',
  domain: 'bar.com'
};

const authClient = AuthClient.build(config);

const identityResult = authClient.getIdentityToken();
if (identityResult.ok) {
  console.log('Identity token:', identityResult.token);
  console.log('User name:', identityResult.name);
  console.log('Roles:', identityResult.roles);
}

const accessResult = authClient.getAccessToken('foo');
if (accessResult.ok) {
  console.log('Access token:', accessResult.token);
}