@nevermined-io/payments
    Preparing search index...

    Function createRequireAuthMiddleware

    • Create a middleware that requires a Bearer token, emitting an RFC 9728 §5.1 WWW-Authenticate challenge on 401 so a client can discover the PRM.

      options.baseUrl (optional) — operator-known public base URL of THIS MCP server. When set, the resource_metadata pointer is built from it (never from client input) — the correct choice behind a TLS-terminating proxy. When omitted, the pointer is derived from the request, but ONLY if the (forwarded) Host is a safe, well-formed value; otherwise the challenge header is omitted rather than emitting a broken/injectable one.

      options.resourceMetadataPath (optional) — the PRM path to advertise; defaults to the root /.well-known/oauth-protected-resource. A caller mounting this on a sub-resource (e.g. /mcp) should pass the scoped document (/.well-known/oauth-protected-resource/mcp) so the client gets the correctly scoped resource (RFC 8707 audience) and the resource's capabilities.

      Parameters

      • options: { baseUrl?: string; resourceMetadataPath?: string } = {}

      Returns (req: Request, res: Response, next: NextFunction) => void