# Litestar Auth Guards

> Auto-activate for guards=, Guard, ASGIConnection, JWTAuth, JWTCookieAuth, SessionAuth, role or tenant checks, or WebSocket auth. Not for frontend route protection.

- **Type:** Skill
- **Install:** `agentstack add skill-litestar-org-litestar-skills-litestar-auth-guards`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [litestar-org](https://agentstack.voostack.com/s/litestar-org)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [litestar-org](https://github.com/litestar-org)
- **Source:** https://github.com/litestar-org/litestar-skills/tree/main/skills/litestar-auth-guards
- **Website:** https://github.com/litestar-org/litestar-skills

## Install

```sh
agentstack add skill-litestar-org-litestar-skills-litestar-auth-guards
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Litestar Auth and Guards

Use this skill for authentication boundaries, authorization checks, guard composition, and user context.

## Code Style Rules

- Put auth and permission checks in Guards or middleware, not handler bodies.
- Prefer Controller-level guards when a whole domain shares a policy.
- Raise Litestar HTTP exceptions or domain exceptions consistently.
- Keep tenant isolation explicit in guard logic and service filters.

## Quick Reference

- Guard patterns: [guards.md](references/guards.md)
- Middleware user loading: [litestar-middleware](../litestar-middleware/SKILL.md)
- Realtime auth: [litestar-realtime](../litestar-realtime/SKILL.md)

## Workflow

1. Determine where identity is loaded.
2. Add Guards at app, Controller, or route scope.
3. Keep permission checks reusable and testable.
4. Verify denial paths and authenticated success paths.

## Guardrails

- Do not inline auth checks in handlers.
- Do not make Guards perform database work repeatedly when middleware can load the user once.
- Do not trust client-supplied tenant IDs without server-side scoping.
- Do not use HTTP-only assumptions for WebSocket auth.

## Validation Checkpoint

- [ ] Guard scope matches the policy scope.
- [ ] Denial paths return the expected status.
- [ ] Handlers contain no duplicated auth branching.
- [ ] WebSocket routes use an explicit browser-compatible auth path.

## Example

```python
from litestar.connection import ASGIConnection
from litestar.exceptions import PermissionDeniedException
from litestar.handlers import BaseRouteHandler

async def requires_active_user(connection: ASGIConnection, _: BaseRouteHandler) -> None:
    if not connection.user or not connection.user.is_active:
        raise PermissionDeniedException("Authentication required")
```

## References Index

- [guards.md](references/guards.md)

## Official References

-  - Litestar documentation
-  - Litestar API reference

## Shared Styleguide Baseline

- [General](../litestar-styleguide/references/general.md)
- [Python](../litestar-styleguide/references/python.md)
- [Litestar](../litestar-styleguide/references/litestar.md)

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [litestar-org](https://github.com/litestar-org)
- **Source:** [litestar-org/litestar-skills](https://github.com/litestar-org/litestar-skills)
- **License:** MIT
- **Homepage:** https://github.com/litestar-org/litestar-skills

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** yes
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-litestar-org-litestar-skills-litestar-auth-guards
- Seller: https://agentstack.voostack.com/s/litestar-org
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
