API Tokens

Secure API token management for Convex with token lifecycle, encryption, validation, and middleware for authentication workflows.

Installation

npm install convex-api-tokens

About API Tokens

Convex component for API token management: issuance, validation, rotation, revocation, and encrypted third-party key storage

Benefits

Use cases

how to add API token authentication to Convex

Use convex-api-tokens to implement secure token authentication in your Convex backend. The component provides createTokenAuth() middleware for HTTP actions and withTokenAuth() for mutations, handling token validation and user context automatically.

secure API key storage in Convex database

Store third-party API keys securely using convex-api-tokens encrypted storage. The component encrypts keys with AES-256-GCM before database storage and provides retrieval methods for use in your Convex functions.

token rotation and revocation in Convex

Implement token lifecycle management with convex-api-tokens rotation and bulk revocation features. You can refresh existing tokens, revoke tokens by namespace, or perform bulk revocation by time range for security compliance.

API token expiration and timeout handling

Configure token expiration and idle timeouts using convex-api-tokens lifecycle management. The validation system returns detailed failure reasons including expired, idle_timeout, revoked, and invalid states for proper error handling.

Frequently asked questions

What token format does convex-api-tokens use?

convex-api-tokens generates sk_-prefixed tokens that follow industry standards. These tokens can be organized by namespaces and include configurable expiration times and idle timeout settings for security compliance.

How does token validation work with detailed error handling?

The convex-api-tokens validation system returns specific failure reasons including expired, idle_timeout, revoked, and invalid states. This allows your application to handle different authentication failures appropriately and provide meaningful error messages.

Can I store and encrypt third-party API keys safely?

Yes, convex-api-tokens provides encrypted storage for third-party API keys like Stripe and OpenAI credentials. It uses AES-256-GCM encryption to secure keys in your Convex database and provides safe retrieval methods.

What middleware options are available for Convex functions?

convex-api-tokens provides createTokenAuth() middleware for HTTP actions and withTokenAuth() middleware for mutations. Both handle token validation automatically and inject user context into your Convex functions with TypeScript support.

How do I implement bulk token revocation by namespace?

convex-api-tokens supports bulk revocation operations by namespace or time range. You can revoke all tokens in a specific namespace or revoke tokens created within a certain time period for security incident response.

Links