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

1import { AuthHandler } from '@signalwire/sdk';
2
3const auth = new AuthHandler({
4 bearerToken: 'sk_live_abc123',
5});
6
7function authorize(header: string | undefined) {
8 const token = header?.replace(/^Bearer\s+/i, '') ?? '';
9 return auth.verifyBearerToken(token);
10}