Latest Socket ResearchMalicious Chrome Extension Performs Hidden Affiliate Hijacking.Details
Socket
Book a DemoInstallSign in
Socket

jwtbased-rbac

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jwtbased-rbac

Role-Based Access Control system with PostgreSQL backend and JWT authentication

pipPyPI
Version
1.0.0
Maintainers
1

JWT-Based RBAC

Role-Based Access Control system with PostgreSQL backend and JWT authentication.

Features

  • 🔐 Database-backed permissions - PostgreSQL storage for roles and permissions
  • 🎫 JWT token management - Create and validate JWT tokens with embedded permissions
  • Permission caching - In-memory caching with configurable TTL
  • 📝 Audit logging - Track all authorization attempts
  • 🔄 Role management - Assign/revoke roles dynamically

Installation

pip install jwtbased-rbac

Quick Start

import asyncpg
from jwtbased_rbac import init_rbac_manager, get_rbac_manager, JWTManager

# Initialize with database pool
pool = await asyncpg.create_pool('postgresql://...')
init_rbac_manager(pool)

# Get manager instance
rbac = get_rbac_manager()

# Check user permission
allowed = await rbac.check_permission('user@example.com', 'admin_tool')

# Get user's permissions
permissions = await rbac.get_user_permissions('user@example.com')

# Create JWT token
token = JWTManager.create_access_token('user@example.com', permissions)

# Decode token
payload = JWTManager.decode_token(token)

Environment Variables

# Required
JWT_SECRET_KEY=your_secret_key_here  # Generate with: python -c 'import secrets; print(secrets.token_urlsafe(32))'

# Optional
RBAC_CACHE_TTL_SECONDS=300           # Cache TTL (default: 300)
RBAC_STRICT_MODE=true                # Deny on errors (default: true)
RBAC_AUDIT_ENABLED=true              # Enable audit log (default: true)
JWT_ALGORITHM=HS256                  # JWT algorithm (default: HS256)
JWT_ACCESS_TOKEN_EXPIRE_MINUTES=30  # Token expiry (default: 30)

License

MIT License

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts