getAuthInfo

View as MarkdownOpen in Claude

Return structured metadata describing each enabled authentication method on this handler. Useful for generating diagnostic pages, startup banners, or developer-facing hints about which auth schemes are active. Missing entries indicate the corresponding method is not configured.

Returns

An object with three optional keys:

basic
{ enabled: true; username: string } | undefined

Present when Basic Auth is configured. Contains the configured username (the password is never returned).

bearer
{ enabled: true; hint: string } | undefined

Present when Bearer token auth is configured. hint is a human-readable string like "Use Authorization: Bearer <token>".

apiKey
{ enabled: true; header: string; hint: string } | undefined

Present when API key auth is configured. header is the configured header name (defaults to "X-Api-Key"). hint is a human-readable usage string.

Example

1import { AuthHandler } from '@signalwire/sdk';
2
3const auth = new AuthHandler({
4 basicAuth: ['admin', 'secret'],
5 bearerToken: 'sk_live_abc123',
6});
7
8const info = auth.getAuthInfo();
9console.log(info);
10// {
11// basic: { enabled: true, username: 'admin' },
12// bearer: { enabled: true, hint: 'Use Authorization: Bearer <token>' }
13// }
14
15if (info.apiKey) {
16 console.log(`API key expected in header ${info.apiKey.header}`);
17}