Registry / security / auth0-cc-token-cache

auth0-cc-token-cache

JSON →
library0.1.0jsnpmunverified

Minimal Auth0 client credentials token acquisition with Redis caching (v0.1.0). Solves M2M token quota limits by caching tokens in Redis with automatic TTL management. Integrates with the official Auth0 SDK (v5+) and ioredis (v5+). Designed for Node.js >=18. Provides a simple `createTokenClient` factory function returning an async `getAccessToken()` method. Cache key includes `clientId` and `audience`; supports configurable prefix and TTL buffer. Ships TypeScript definitions. Low dependency footprint but requires peer dependencies `auth0` and `ioredis`. Not battle-tested; experimental release.

npm install auth0-cc-token-cache
INSTALL
IMPORT
SIG · AUTH0-CC-TOKEN-CAC
A
auth0-cc-token-cache
securityjavascriptv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createTokenClient
import { createTokenClient } from 'auth0-cc-token-cache'
import createTokenClient from 'auth0-cc-token-cache'
Named export, not default. TypeScript ships types.
Auth0CCTokenClient
import type { Auth0CCTokenClient } from 'auth0-cc-token-cache'
import { Auth0CCTokenClient } from 'auth0-cc-token-cache'
TypeScript type import only; not a runtime value.
TokenClientConfig
import type { TokenClientConfig } from 'auth0-cc-token-cache'
const { TokenClientConfig } = require('auth0-cc-token-cache')
Config type is exported for type usage only.

Demonstrates creating a token client with Auth0 config and Redis cache, then retrieving an access token.

import { createTokenClient } from 'auth0-cc-token-cache'; import Redis from 'ioredis'; const redis = new Redis(process.env.REDIS_URL ?? 'redis://localhost:6379'); const tokenClient = createTokenClient({ auth0: { domain: process.env.AUTH0_DOMAIN ?? 'your-tenant.auth0.com', clientId: process.env.AUTH0_CLIENT_ID ?? '', clientSecret: process.env.AUTH0_CLIENT_SECRET ?? '', }, audience: process.env.AUTH0_AUDIENCE ?? 'https://your-api.example.com', cache: { redis, keyPrefix: 'my-app', ttlBuffer: 60, }, }); const token = await tokenClient.getAccessToken(); console.log(token);
Debug
Known issues
gotchaRequires peer dependencies `auth0` and `ioredis` to be installed separately.
fix
Run `npm install auth0 ioredis` alongside this package.
affects: >=0.0.0
gotchaNode.js >=18 required; older versions not supported.
fix
Upgrade Node.js to version 18 or later.
affects: >=0.0.0
gotchaThe `auth0` peer dependency must be version 5 or higher.
fix
Ensure your project has `"auth0": "^5.0.0"` in dependencies.
affects: >=0.0.0
gotchaThe `ioredis` peer dependency must be version 5 or higher.
fix
Ensure your project has `"ioredis": "^5.0.0"` in dependencies.
affects: >=0.0.0
gotchaCache key includes `clientId` and `audience`; ensure these are consistent across requests.
fix
Use the same `clientId` and `audience` for all calls to avoid cache misses.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'auth0'
Missing peer dependency `auth0`.
fix
Run `npm install auth0`
TypeError: redis.get is not a function
Passed invalid Redis instance (not an ioredis client).
fix
Ensure you pass an instance of `ioredis` (e.g., `new Redis()`) to the `cache.redis` option.
Error: Auth0 domain is required
Missing `auth0.domain` in config.
fix
Provide `domain` in the `auth0` config object as a non-empty string.
TypeError: createTokenClient is not a function
Default import used instead of named import.
fix
Use `import { createTokenClient } from 'auth0-cc-token-cache'`.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
auth0requiredPeer dependency: official Auth0 SDK used for client credentials grant token acquisition
ioredisrequiredPeer dependency: Redis client for token caching
Agent activity
26 hits · last 30 days
node
26
Resources
auth0-cc-token-cache — npm install auth0-cc-token-cache · libregistry