mi6-game-token-manager
v1.0.0
Published
Token and API Key management utility for MI6 ecosystem
Readme
MI6 Token Manager
A utility package for managing JWT tokens and API Keys within the MI6 ecosystem.
Installation
You can install this package locally in your project:
npm install ../packages/mi6-token-manager(Adjust the path depending on where your project is located relative to the packages folder)
Usage
JWT Management
const { JwtManager } = require('mi6-token-manager');
// Initialize with your secret key
const jwtManager = new JwtManager('your-secret-key');
// Generate Token
const token = jwtManager.generateToken({ id: 1, username: 'admin' });
// Verify Token
const payload = jwtManager.verifyToken(token);
// Use as Express Middleware
app.get('/protected', jwtManager.middleware(), (req, res) => {
res.json({ message: 'You have access!', user: req.user });
});API Key Management
const { ApiKeyManager } = require('mi6-token-manager');
// Initialize with valid API keys
const apiKeyManager = new ApiKeyManager(['mi6-slot-api-key', 'another-key']);
// Add a new key dynamically (e.g. when registering a new game)
apiKeyManager.addKey('new-game-secret-key');
// Remove a key (e.g. when banning a game)
apiKeyManager.removeKey('old-compromised-key');
// Use as Express Middleware
app.use('/api/public', apiKeyManager.middleware());