jwt-scg
v1.1.2
Published
A simple, secure, and universal JWT library for web and mobile applications - built by SCG
Maintainers
Readme
SCG JWT Token - Universal JWT Library
A simple, secure, and universal JWT library available for Node.js and Python. Zero external dependencies, lightweight, and built for enterprise security.
Built by Analytics With Harry and Squid Consultancy Group Limited
Installation
Node.js / JavaScript
npm install jwt-scgPython
pip install scg-jwt-tokenQuick Start
Node.js / JavaScript
const SCGJwtToken = require('jwt-scg');
// Initialize
const jwt = new SCGJwtToken('your-secret-key');
// Create token
const token = jwt.sign({ userId: '12345', email: '[email protected]' });
// Verify token
const payload = jwt.verify(token);
console.log(payload); // { userId: '12345', email: '[email protected]', ... }Python
from scg_jwt_token import SCGJwtToken
# Initialize
jwt = SCGJwtToken("your-secret-key")
# Create token
token = jwt.sign({"user_id": "12345", "email": "[email protected]"})
# Verify token
payload = jwt.verify(token)
print(payload) # {"user_id": "12345", "email": "[email protected]", ...}Key Features
| Feature | Node.js | Python | |---------|---------|---------| | Zero Dependencies | ✅ Native crypto module only | ✅ Standard library only | | TypeScript Support | ✅ Full type definitions | ✅ Type hints included | | Performance Tracking | ✅ Built-in statistics | ✅ Performance monitoring | | Security Features | ✅ HMAC-SHA256, DoS protection | ✅ HMAC-SHA256, secure defaults | | Framework Support | ✅ Express, React, Vue, Angular | ✅ Django, Flask, FastAPI | | Mobile Ready | ✅ React Native compatible | ✅ Cross-platform |
Advanced Usage
Batch Operations (Node.js)
const tokens = jwt.signBatch([
{ userId: '1', role: 'admin' },
{ userId: '2', role: 'user' }
]);
const results = jwt.verifyBatch(tokens);Security Analysis (Node.js)
const analysis = jwt.analyzeTokenSecurity(token);
console.log(analysis.strength); // 'Strong', 'Medium', 'Weak'Custom Claims (Both platforms)
// Node.js
const token = jwt.sign(payload, {
expiresIn: 3600,
issuer: 'my-app',
audience: 'mobile-users'
});
// Python
token = jwt.sign(payload,
expires_in=3600,
issuer='my-app',
audience='mobile-users')Repository Structure
jwt-scg/
├── <File /> README.md # Main documentation
├── <File /> package.json # Node.js package config
├── <File /> index.js # Node.js main library
├── <File /> index.d.ts # TypeScript definitions
├── <Folder /> examples/ # Usage examples
│ ├── backend-example.js # Express.js integration
│ ├── frontend-example.js # React/Vue usage
│ └── mobile-react-native.js # React Native
├── <Folder /> test/ # Test suites
├── <Folder /> python/ # Python package
│ ├── <File /> setup.py # Python package config
│ ├── <File /> README.md # Python documentation
│ ├── <Folder /> scg_jwt_token/ # Python source
│ └── <File /> test_scg_jwt.py # Python tests
└── <File /> LICENSE # MIT LicenseFramework Integration
Express.js Middleware
const authMiddleware = (req, res, next) => {
const token = req.headers.authorization?.replace('Bearer ', '');
try {
req.user = jwt.verify(token);
next();
} catch (error) {
res.status(401).json({ error: 'Invalid token' });
}
};
app.use('/api/protected', authMiddleware);Django Middleware
from django.http import JsonResponse
from scg_jwt_token import SCGJwtToken
class JWTMiddleware:
def __init__(self, get_response):
self.get_response = get_response
self.jwt = SCGJwtToken(settings.SECRET_KEY)
def __call__(self, request):
auth_header = request.META.get('HTTP_AUTHORIZATION', '')
if auth_header.startswith('Bearer '):
token = auth_header[7:]
try:
request.user_data = self.jwt.verify(token)
except ValueError:
return JsonResponse({'error': 'Invalid token'}, status=401)
return self.get_response(request)Performance & Security
Security Features
- HMAC-SHA256: Industry standard algorithm
- DoS Protection: 64KB payload limit (Node.js)
- Timing Attack Prevention: Constant-time comparison
- No External Dependencies: Reduced attack surface
Performance Benchmarks
- Node.js: 50,000+ tokens/second
- Python: 25,000+ tokens/second
- Memory Usage: <2MB footprint
- Startup Time: <10ms initialization
Package Links
| Platform | Package | Repository | |----------|---------|------------| | npm | jwt-scg | Node.js/TypeScript | | PyPI | scg-jwt-token | Python 3.7+ | | GitHub | analyticswithharry/scg-jwt-token | Source Code |
About the Authors
Analytics With Harry - Squid Consultancy Group Limited
We specialize in building secure, scalable software solutions for enterprises and startups worldwide.
- Email: [email protected]
- Company Email: [email protected]
- GitHub: @analyticswithharry
- Website: squidconsultancy.com
- Social: @analyticswithharry
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Star History
If you find this project helpful, please consider giving it a star on GitHub!
Made with by Squid Consultancy Group Limited
