🐺 Initial commit - Lupul Augmentat MCP Server
- MCP server cu stdio transport pentru performanță maximă
- Tool-uri pentru file operations, HTTP requests, system commands
- Suport NATS pentru comunicare inter-module
- Configurare nginx cu API key auth și SSL
- Arhitectură modulară și extensibilă
🤖 Generated with Claude Code
This commit is contained in:
94
src/auth/generate-token.ts
Normal file
94
src/auth/generate-token.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env node
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { config } from '../config';
|
||||
|
||||
// Script pentru generarea token-urilor JWT
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
if (args.length < 1 || args.includes('--help') || args.includes('-h')) {
|
||||
console.log(`
|
||||
Usage: generate-token [options]
|
||||
|
||||
Options:
|
||||
--id <user-id> User ID (default: admin)
|
||||
--permissions <perms> Comma-separated permissions (default: all)
|
||||
--expires <duration> Token expiration (e.g., 1h, 7d, 30d) (default: 30d)
|
||||
--secret <secret> JWT secret (default: from config)
|
||||
|
||||
Examples:
|
||||
# Generate admin token with all permissions
|
||||
npm run generate-token
|
||||
|
||||
# Generate limited token
|
||||
npm run generate-token -- --id user123 --permissions file:read,file:list --expires 1h
|
||||
|
||||
Available permissions:
|
||||
- file:read
|
||||
- file:write
|
||||
- file:list
|
||||
- system:exec
|
||||
- network:http
|
||||
`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// Parse arguments
|
||||
const getArg = (name: string, defaultValue: string): string => {
|
||||
const index = args.indexOf(`--${name}`);
|
||||
if (index === -1 || index + 1 >= args.length) {
|
||||
return defaultValue;
|
||||
}
|
||||
return args[index + 1] || defaultValue;
|
||||
};
|
||||
|
||||
const userId = getArg('id', 'admin');
|
||||
const permissionsStr = getArg('permissions', 'file:read,file:write,file:list,system:exec,network:http');
|
||||
const expires = getArg('expires', '30d');
|
||||
const secret = getArg('secret', config.security.jwtSecret);
|
||||
|
||||
const permissions = permissionsStr.split(',').map(p => p.trim());
|
||||
|
||||
// Generate token
|
||||
const payload = {
|
||||
id: userId,
|
||||
permissions,
|
||||
iat: Math.floor(Date.now() / 1000),
|
||||
};
|
||||
|
||||
const options: jwt.SignOptions = {
|
||||
expiresIn: expires as any,
|
||||
};
|
||||
|
||||
const token = jwt.sign(payload, secret, options);
|
||||
|
||||
console.log('\n🔐 JWT Token Generated:');
|
||||
console.log('='.repeat(80));
|
||||
console.log(token);
|
||||
console.log('='.repeat(80));
|
||||
console.log('\nToken Details:');
|
||||
console.log(` User ID: ${userId}`);
|
||||
console.log(` Permissions: ${permissions.join(', ')}`);
|
||||
console.log(` Expires: ${expires}`);
|
||||
console.log('\n📋 Usage Examples:');
|
||||
console.log('\nHTTP Header:');
|
||||
console.log(` Authorization: Bearer ${token}`);
|
||||
console.log('\ncURL:');
|
||||
console.log(` curl -X POST https://mcp.runningwolf.com/ \\
|
||||
-H "Authorization: Bearer ${token}" \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'`);
|
||||
console.log('\nJavaScript:');
|
||||
console.log(` fetch('https://mcp.runningwolf.com/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ${token}',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
jsonrpc: '2.0',
|
||||
id: 1,
|
||||
method: 'tools/list',
|
||||
params: {}
|
||||
})
|
||||
})`);
|
||||
console.log();
|
||||
Reference in New Issue
Block a user