validate

View as MarkdownOpen in Claude

Validate request headers against configured auth methods (Bearer, API Key, Basic, Custom) in order. Returns true if any configured method accepts the request, or if no methods are configured and allowUnauthenticated is not false.

Parameters

headers
Record<string, string>Required

The request headers as a string-keyed record. The method checks both lowercase and title-case header names (e.g., authorization and Authorization).

Returns

Promise<boolean>true if the request is authorized.

Example

1import { AuthHandler } from '@signalwire/sdk';
2
3const auth = new AuthHandler({
4 bearerToken: 'my-secret-token',
5});
6
7// Validate headers from an incoming request
8const isValid = await auth.validate({
9 authorization: 'Bearer my-secret-token',
10});
11console.log('Authorized:', isValid); // true