@hsuite/api-key
A comprehensive NestJS module for API key-based authentication, providing a complete solution for protecting routes and validating API keys in your application.
Features
🔐 API key validation and authentication
🛡️ Route protection through guards
🔄 Passport.js integration
🌐 Global or feature-module registration
📦 Built-in user integration
🔑 Bearer token support in Authorization header
Installation
Peer Dependencies
This module requires the following peer dependencies:
Quick Start
Import the module in your
app.module.ts
:
Protect your routes using the guard:
API Reference
ApiKeyModule
The main module that provides API key authentication functionality.
Methods
forRoot()
: Registers the module globally in your application.
ApiKeyService
Service responsible for API key operations and validation.
Methods
validateApiKey(apiKey: string, user: UserDocument): Promise<User>
Validates an API key against a user's stored credentials
Returns the user object if valid, null otherwise
ApiKeyAuthGuard
Guard that protects routes requiring API key authentication.
ApiKeyStrategy
Passport strategy implementation for API key authentication.
Usage Examples
Protecting Routes
Making Authenticated Requests
Clients should include the API key in the Authorization header using the Bearer scheme:
Validating API Keys
Architecture
The module consists of several key components:
ApiKeyModule: The main module that ties everything together
ApiKeyService: Handles API key validation and management
ApiKeyAuthGuard: Protects routes requiring authentication
ApiKeyStrategy: Implements the Passport.js authentication strategy
Documentation
Detailed documentation can be generated using Compodoc:
To check documentation coverage:
Version
Current version: 2.0.0
License
This package is part of the HSuite Enterprise solution.
Built with ❤️ by the HbarSuite Team Copyright © 2024 HbarSuite. All rights reserved.
Last updated