litestar-auth-guards

Implement JWT and session authentication guards for Litestar HTTP and WebSocket endpoints.

13|Updated Apr 15, 2026
One-click install
npx skills add https://github.com/litestar-org/litestar-skills --skill litestar-auth-guards
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: litestar-auth-guards
Source: https://github.com/litestar-org/litestar-skills/tree/main/plugins/litestar/skills/litestar-auth-guards
Command: npx skills add https://github.com/litestar-org/litestar-skills --skill litestar-auth-guards

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Manually writing authentication and authorization logic directly in Litestar route handlers creates duplicated code, inconsistent security policies, and increased vulnerability risk, especially for complex use cases like WebSocket authentication and multi-tenant access control.

Core Features & Use Cases

  • Pre-built Guard Patterns: Ready-to-use guard implementations for common auth scenarios including JWT bearer token validation, session authentication, multi-tenant membership checks, and WebSocket-compatible auth flows.
  • Scope-aware Guard Composition: Guidance on applying guards at the correct level (application, controller, or route) to avoid redundant logic and ensure consistent policy enforcement across your Litestar service.
  • Validation & Safety Guardrails: Built-in validation checkpoints and explicit guardrails to prevent common auth mistakes like inline handler checks, repeated database queries for user data, and trust in untrusted client-supplied tenant IDs.
  • Real-world Use Case: For a multi-tenant Litestar application with both HTTP REST endpoints and WebSocket real-time features, use this skill to implement a unified, secure auth guard system that works across all endpoint types, eliminating duplicated auth logic and closing security gaps.

Quick Start

Use the litestar-auth-guards skill to add JWT authentication and multi-tenant authorization guards to your Litestar application's routes and controllers.

Frequently Asked Questions about litestar-auth-guards

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

FAQPage Schema
How do I implement JWT authentication in Litestar without duplicating logic in every route handler?

To implement JWT authentication in Litestar without duplicating logic, you can use pre-built guard patterns that apply secure, reusable authorization checks at the application, controller, or route level to ensure consistent policy enforcement.

Can I secure WebSocket endpoints with authentication guards in Litestar?

Yes, you can secure WebSocket endpoints in Litestar using WebSocket-compatible authentication flows provided by guard components, which handle user context loading and consistent denial paths specifically designed for real-time endpoint protection.

What is the best way to handle multi-tenant access control in a Litestar application?

The best way to handle multi-tenant access control in Litestar is by applying scope-aware guard compositions that perform membership checks while preventing common security mistakes like trusting unverified client-supplied tenant IDs.

How do Litestar guards prevent repeated database queries for user data during authorization?

Litestar guards prevent repeated database queries for user data by utilizing built-in validation checkpoints and guardrails that ensure proper user context loading is handled efficiently without redundant inline handler checks.

Does Litestar support session authentication alongside JWT bearer token validation?

Yes, Litestar supports session authentication alongside JWT bearer token validation through ready-to-use guard implementations that cover both workflows, allowing you to apply the appropriate authentication mechanism across your HTTP and WebSocket endpoints.

Why should I avoid inline auth checks in Litestar route handlers?

You should avoid inline auth checks in Litestar route handlers because they create duplicated code, inconsistent security policies, and increased vulnerability risk, which reusable guard components eliminate by centralizing authorization logic.