Skip to content

@salesforce/b2c-tooling-sdk / auth / ApiKeyStrategy

Class: ApiKeyStrategy

Defined in: packages/b2c-tooling-sdk/src/auth/api-key.ts:26

API Key authentication strategy.

Supports two modes:

  • Bearer token: When headerName is 'Authorization', formats as 'Bearer {key}'
  • Direct key: For other headers (e.g., 'x-api-key'), sets the key directly

Examples

ts
// For MRT API (Bearer token)
const auth = new ApiKeyStrategy(apiKey, 'Authorization');
// Sets: Authorization: Bearer {apiKey}
ts
// For custom API key header
const auth = new ApiKeyStrategy(apiKey, 'x-api-key');
// Sets: x-api-key: {apiKey}

Implements

Constructors

Constructor

new ApiKeyStrategy(key, headerName): ApiKeyStrategy

Defined in: packages/b2c-tooling-sdk/src/auth/api-key.ts:30

Parameters

key

string

headerName

string = 'x-api-key'

Returns

ApiKeyStrategy

Methods

fetch()

fetch(url, init): Promise<Response>

Defined in: packages/b2c-tooling-sdk/src/auth/api-key.ts:43

Performs a fetch request with authentication. Implementations MUST handle header injection and 401 retries (token refresh) internally.

Parameters

url

string

init

RequestInit = {}

Returns

Promise<Response>

Implementation of

AuthStrategy.fetch


getAuthorizationHeader()

getAuthorizationHeader(): Promise<string>

Defined in: packages/b2c-tooling-sdk/src/auth/api-key.ts:52

Returns the authorization header value for use with openapi-fetch middleware.

Returns

Promise<string>

Implementation of

AuthStrategy.getAuthorizationHeader

All rights reserved.