For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
GuidesReference
GuidesReference
    • Core
      • Overview
    • Agents
      • Overview
      • AgentBase
      • AgentServer
      • Configuration
        • AuthHandler
          • expressMiddleware
          • getAuthInfo
          • hasApiKeyAuth
          • hasBasicAuth
          • hasBearerAuth
          • middleware
          • validate
          • verifyApiKey
          • verifyBasicAuth
          • verifyBearerToken
        • ConfigLoader
        • Environment Variables
        • Logging
        • PromptManager
        • SchemaUtils
        • ServerlessAdapter
        • SessionManager
        • SslConfig
      • ContextBuilder
      • DataMap
      • FunctionResult
      • Helper Functions & Utilities
      • LiveWire
      • PomBuilder
      • Prefabs
      • SkillBase
      • SkillManager
      • SkillRegistry
      • Skills
      • SwaigFunction
      • SwmlBuilder
      • SWMLService
    • RELAY
      • Overview
      • Actions
      • Call
      • Constants
      • Events
      • Message
      • RelayClient
      • RelayError
    • REST Client
      • Overview
      • Addresses
      • Calling
      • ChatResource
      • Compat
      • Datasphere
      • Fabric
      • ImportedNumbersResource
      • Logs
      • LookupResource
      • MFA
      • Number Groups
      • Phone Numbers
      • Project
      • PubSubResource
      • Queues
      • Recordings
      • Registry
      • RestClient
      • RestError
      • Short Codes
      • SIP Profile
      • Verified Callers
      • Video
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Parameters
  • Returns
  • Example
AgentsConfigurationAuthHandler

expressMiddleware

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

getAuthInfo

Next
Built with

Create an Express/Connect-compatible middleware function that validates incoming requests against the configured authentication methods and returns a 401 Unauthorized response when auth fails. Framework-agnostic equivalent of the Python SDK’s get_fastapi_dependency.

For Hono apps, use middleware() instead. For standalone validation without a framework, use validate() directly.

Parameters

optional
booleanDefaults to false

When true, unauthenticated requests are allowed through instead of being rejected. Useful for progressive-auth flows where the handler downstream decides whether to require credentials.

Returns

An async Express-compatible middleware: (req, res, next) => Promise<void>.

On failed auth with optional=false, responds with HTTP 401 and body { error: 'Unauthorized' }. On success or when optional=true, calls next().

Example

1import express from 'express';
2import { AuthHandler } from '@signalwire/sdk';
3
4const auth = new AuthHandler({
5 bearerToken: 'sk_live_abc123',
6});
7
8const app = express();
9
10// Protect all /api/* routes
11app.use('/api', auth.expressMiddleware());
12
13app.get('/api/status', (req, res) => {
14 res.json({ ok: true });
15});
16
17// Public route with optional auth
18app.get('/public', auth.expressMiddleware(true), (req, res) => {
19 res.json({ authenticated: false });
20});