validateBasicAuth

View as MarkdownOpen in Claude

Lifecycle hook for custom basic-auth validation. The default implementation returns true. Subclasses can override this to add secondary validation logic (e.g., database lookups, external identity providers).

This hook is defined but not yet called by the built-in Hono basicAuth middleware. The middleware currently validates credentials directly against the stored username/password pair. Overriding this method will have no effect on request authentication in the current SDK version. It is reserved for future integration.

Parameters

username
stringRequired

Username extracted from the incoming request’s Authorization header.

password
stringRequired

Password extracted from the incoming request’s Authorization header.

Returns

boolean | Promise<boolean>true if the credentials are valid, false to reject the request.

Example

1import { AgentBase } from '@signalwire/sdk';
2
3class SecureAgent extends AgentBase {
4 constructor() {
5 super({ name: 'assistant', route: '/assistant' });
6 this.setPromptText('You are a helpful assistant.');
7 }
8
9 override async validateBasicAuth(
10 username: string,
11 password: string,
12 ): Promise<boolean> {
13 // Custom validation against an external user store
14 const response = await fetch('https://auth.example.com/verify', {
15 method: 'POST',
16 headers: { 'Content-Type': 'application/json' },
17 body: JSON.stringify({ username, password }),
18 });
19 return response.ok;
20 }
21}
22
23const agent = new SecureAgent();
24await agent.serve();