Skip to content

@salesforce/b2c-tooling-sdk / auth

auth

Authentication strategies for B2C Commerce APIs.

This module provides different authentication mechanisms for connecting to B2C Commerce instances and platform services.

Available Strategies

Strategy Resolution

Use resolveAuthStrategy to automatically select the best strategy based on available credentials and allowed methods:

typescript
import { resolveAuthStrategy } from '@salesforce/b2c-tooling-sdk';

// Automatically picks client-credentials if secret available, otherwise implicit
const strategy = resolveAuthStrategy({
  clientId: 'your-client-id',
  clientSecret: process.env.CLIENT_SECRET, // may be undefined
});

// Force a specific method
const implicitOnly = resolveAuthStrategy(
  { clientId: 'your-client-id' },
  { allowedMethods: ['implicit'] }
);

Direct Usage

All strategies implement the AuthStrategy interface:

typescript
import { OAuthStrategy, ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk';

// For automated/server usage (client credentials)
const oauthAuth = new OAuthStrategy({
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
});

// For interactive/CLI usage (opens browser)
const implicitAuth = new ImplicitOAuthStrategy({
  clientId: 'your-client-id',
});

Classes

Interfaces

Type Aliases

Variables

Functions

All rights reserved.