portal-auth-jwt

Implements JWT authentication and role-based authorization in FastAPI with PyJWT and Argon2.

Updated Jul 27, 2026
One-click install
npx skills add https://github.com/ArthurZizumbo/karisma-data --skill portal-auth-jwt-arthurzizumbo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: portal-auth-jwt
Source: https://github.com/ArthurZizumbo/karisma-data/tree/main/.claude/skills/portal-auth-jwt
Command: npx skills add https://github.com/ArthurZizumbo/karisma-data --skill portal-auth-jwt-arthurzizumbo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pyjwt, pwdlib, fastapi, httpx.

What problem does it solve? Building secure authentication and authorization for a FastAPI backend requires many coordinated decisions: password hashing, token issuance, role enforcement, timing-attack protection, and frontend session handling. This Skill encodes a verified, opinionated implementation so these security-critical pieces are built correctly and consistently. ## Core Features & Use Cases - JWT auth with PyJWT HS256: Issues 30-minute access tokens carrying sub and scope claims, validated via OAuth2PasswordBearer and SecurityScopes. - Role-based permission matrix: Enforces the operativo/analista/directivo/admin hierarchy across endpoints, returning 401 with WWW-Authenticate or 403 as appropriate. - Hardened user management: Argon2id hashing via pwdlib, dummy-hash verification against timing attacks, admin-only CRUD with self-demotion and duplicate protections, and soft delete effective on the next request. - Use Case: When adding a new protected endpoint like /api/export, apply the Skill to wire Security(get_current_user, scopes=["analista"]) correctly and propagate the user's Bearer token to agent tool calls so the agent never sees data the user cannot access. ## Quick Start Use the portal-auth-jwt skill to implement the login endpoint and get_current_user dependency in backend/app/core/auth.py following the official FastAPI security pattern.

Frequently Asked Questions about portal-auth-jwt

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement JWT authentication in FastAPI with PyJWT?

Create an OAuth2PasswordBearer scheme pointing at your token endpoint, encode tokens with PyJWT using HS256 and a 32-byte secret, and decode them in a get_current_user dependency. Include sub and scope claims with a 30-minute expiration.

How to enforce role-based access control with FastAPI SecurityScopes?

Pass scopes to Security(get_current_user, scopes=["admin"]) on each endpoint, then compare the token's role claim against required scopes using a role hierarchy. Return 401 for invalid tokens and 403 for authenticated users lacking permission.

Why verify a dummy hash when the login user does not exist?

Verifying a dummy Argon2 hash when the username is missing keeps response time constant, preventing timing attacks that reveal whether an account exists. pwdlib's PasswordHash.recommended() provides the Argon2id hashing used for both real and dummy verification.

Does this JWT approach support refresh tokens?

No, refresh tokens are explicitly out of scope by design decision. Tokens expire after 30 minutes and users re-login cleanly, which simplifies revocation and reduces token-theft exposure.

How do I propagate a user's Bearer token to agent tool calls?

Pass the user's Bearer token into each tool's HTTP call via the Authorization header when calling governed API endpoints. A 403 from the downstream endpoint means the user lacks the required scope, and that error should be surfaced rather than bypassed.

What happens when an admin disables a user account?

Deletion is a soft delete setting disabled=true, and get_current_user rejects disabled users so the block takes effect on the next request. An admin cannot deactivate or demote themselves, and duplicate usernames or emails return 409.