Skip to navigation

validateBasicAuth

View as MarkdownOpen in Claude

Check a request’s basic-auth credentials. Every route that requires basic auth calls it. The default compares them with the agent’s credentials in constant time and returns false when the agent has no credentials. Override it to check credentials another way, such as a database lookup or an external identity provider.

An override replaces the comparison. Call super.validateBasicAuth() to keep it.

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

import { AgentBase } from '@signalwire/sdk';
class SecureAgent extends AgentBase {
constructor() {
super({ name: 'assistant', route: '/assistant' });
this.setPromptText('You are a helpful assistant.');
}
override async validateBasicAuth(
username: string,
password: string,
): Promise<boolean> {
if (await super.validateBasicAuth(username, password)) return true;
// Fall back to an external user store
const response = await fetch('https://auth.example.com/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password }),
});
return response.ok;
}
}
const agent = new SecureAgent();
await agent.serve();