{"id":18200,"library":"cf-auth-middleware","title":"cf-auth-middleware","description":"Express middleware for authenticating API requests using cf-auth-provider and request signing. Provides HMAC-based authentication via headers or query parameters, with custom TTL and per-request entity injection. Supports Node >=4. Designed for use with cf-signature for client-side signing. Configurable logger, request property, and query key filtering. Stable v3 series with minimal API changes.","status":"active","version":"3.1.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/clocklimited/cf-auth-middleware","tags":["javascript"],"install":[{"cmd":"npm install cf-auth-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add cf-auth-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add cf-auth-middleware","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency providing authentication logic","package":"cf-auth-provider","optional":false}],"imports":[{"note":"Package is CommonJS-only; no default ESM export. Use require().","wrong":"import createAuthMiddleware from 'cf-auth-middleware'","symbol":"createAuthMiddleware","correct":"const createAuthMiddleware = require('cf-auth-middleware')"},{"note":"authProvider is mandatory; options is optional.","wrong":"const authMiddleware = createAuthMiddleware()","symbol":"middleware (returned by createAuthMiddleware)","correct":"const authMiddleware = createAuthMiddleware(authProvider, options)"},{"note":"Export is a single function directly, not an object with named property.","wrong":"const { createAuthMiddleware } = require('cf-auth-middleware')","symbol":"createAuthMiddleware (as named import attempt)","correct":"const createAuthMiddleware = require('cf-auth-middleware')"}],"quickstart":{"code":"var express = require('express');\nvar createAuthMiddleware = require('cf-auth-middleware');\nvar authProvider = require('cf-auth-provider')(myCollection, hashFn);\nvar app = express();\nvar authMiddleware = createAuthMiddleware(authProvider, {\n  reqProperty: 'user',\n  logger: console\n});\napp.get('/private', authMiddleware, function (req, res) {\n  res.send(`Hello ${req.user || 'unknown'}`);\n});\napp.listen(3000);","lang":"javascript","description":"Shows basic setup: create auth middleware with provider and apply to a route."},"warnings":[{"fix":"Add custom query keys to options.ignoreQueryKeys array.","message":"Query string parameters must match exactly; extra keys like cachebusting params will cause signature mismatch unless ignored via options.ignoreQueryKeys.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update to v3 and review custom options.","message":"v2 deprecated; v3 changed default reqProperty from 'authedClient' to 'authedClient' (same) but removed some undocumented options.","severity":"breaking","affected_versions":">=2.0.0 <3.0.0"},{"fix":"Initialize auth provider with your collection and hash function before creating middleware.","message":"Cannot be used without cf-auth-provider; signature verification requires a pre-configured provider instance.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Validate client sends x-cf-ttl as number in milliseconds.","message":"TTL is parsed as milliseconds; ensure client sends x-cf-ttl as integer string.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Replace import with const createAuthMiddleware = require('cf-auth-middleware');","cause":"Using ES6 import syntax with CommonJS package.","error":"TypeError: createAuthMiddleware is not a function"},{"fix":"Ensure client includes x-cf-date in header or query string.","cause":"Request missing required date header or query parameter.","error":"Error: authentication failed - missing x-cf-date header"},{"fix":"Provide a logger object with those methods or omit (defaults to console).","cause":"options.logger is missing required methods (debug, info, warn, error).","error":"TypeError: Cannot read property 'debug' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}