verifyBearerToken

View as MarkdownOpen in Claude

Verify a Bearer token against the configured token. Uses a constant-time comparison to prevent timing attacks. Returns false immediately when Bearer token auth is not configured.

Pass the raw token — do not include the "Bearer " prefix. For full header-based validation (including prefix parsing), use validate().

Parameters

token
stringRequired

The Bearer token string to verify, without the "Bearer " prefix.

Returns

booleantrue if the token matches; false if it doesn’t, or if Bearer auth was not configured.

Example

import { AuthHandler } from '@signalwire/sdk';
const auth = new AuthHandler({
bearerToken: 'sk_live_abc123',
});
function authorize(header: string | undefined) {
const token = header?.replace(/^Bearer\s+/i, '') ?? '';
return auth.verifyBearerToken(token);
}