verifyApiKey

View as MarkdownOpen in Claude

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

Pass only the key value — this method does not parse headers. For full header-based validation (which reads the configured apiKeyHeader, case- insensitive), use validate().

Parameters

key
stringRequired

The API key string to verify.

Returns

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

Example

1import { AuthHandler } from '@signalwire/sdk';
2
3const auth = new AuthHandler({
4 apiKey: 'sk_live_abc123',
5 apiKeyHeader: 'X-Api-Key',
6});
7
8function authorize(headerValue: string | undefined) {
9 if (!headerValue) return false;
10 return auth.verifyApiKey(headerValue);
11}