auth-and-security
Skill1 starsChanged 3 months agoMITView on GitHub
Use when adding authentication, authorization, guards, or security middleware in a Lexigram application
In this repository17 other files it gives its agents.
- ai-subsystem-quickstartSkill
- caching-patternsSkill
- cli-code-generationSkill
- cli-config-and-inspectSkill
- cli-database-operationsSkill
- cli-project-scaffoldingSkill
- configuration-managementSkill
- creating-providers-and-modulesSkill
- database-repository-patternSkill
- events-and-messagingSkill
- lexigram-uiSkill
- multimedia-generationSkill
- real-time-webSkill
- resilience-patternsSkill
- testing-with-lexigramSkill
- using-result-and-error-codesSkill
- web-controllers-and-routingSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 88
Use AuthModule.stub() in tests — in-memory store, fixed dev secret.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Auth and Security
Overview
Lexigram-auth provides JWT-based authentication, RBAC, and web-layer guards. The bundle is wired by AuthModule, which exports AuthenticatorProtocol, AuthorizerProtocol, TokenManagerProtocol, and PasswordHasherProtocol. In DI you normally resolve AuthenticationService (login/register), AuthProviderProtocol (async verify), or JWTTokenManager (tokens).
Core Pattern
from lexigram.auth.authn.services import AuthenticationService
from lexigram.contracts.auth.exceptions import InvalidCredentialsError
from lexigram.result import Err, Ok, Result
class LoginService:
def __init__(self, auth_service: AuthenticationService,
tokens: TokenManagerProtocol):
self.auth = auth_service # constructor injection
self.tokens = tokens
async def login(self, email: str, password: str) -> Result[str, str]:
result = await self.auth.authenticate_user(email, password)
match result:
case Err(InvalidCredentialsError()) | Err(_):
return Err("invalid credentials")
case Ok(user):
token = self.tokens.create_token(user)
return Ok(token.access_token)
def require_admin(self, token: str) -> bool:
verified = self.tokens.verify_token(token) # sync, Result[VerifiedToken, TokenError]
match verified:
case Ok(vt):
return "admin" in vt.roles # VerifiedToken.roles: list[str]
case Err(_):
return FalseFor async verification resolve AuthProviderProtocol (await provider.verify_token(token)), not AuthenticatorProtocol — the bundle never binds it.
Guards
from lexigram.web.security import AuthGuard, RoleGuard, use_guards
# RoleGuard takes an authorizer via constructor injection
@use_guards(AuthGuard(), RoleGuard("admin", authorizer=my_authorizer))
@get("/admin/users")
async def admin_list(self, request):
...Custom guards implement GuardProtocol.can_activate(context); check request.state.user (set by auth middleware).
Provider Config
auth:
secret_key: ${JWT_SECRET} # >= 32 bytes for HS algorithms
token:
secret_key: ${JWT_SECRET}
algorithm: HS256
access_token_expire: 60m
refresh_token_expire: 7dEnv override prefix: LEX_AUTH__.
Module Registration
from lexigram.auth import AuthModule
from lexigram.auth.config import AuthConfig
@module(imports=[AuthModule.configure(AuthConfig(
secret_key=os.environ["JWT_SECRET"],
token=JWTConfig(secret_key=os.environ["JWT_SECRET"]),
))])
class AppModule(Module): ...
# later: service = await container.resolve(AuthenticationService)Use AuthModule.stub() in tests — in-memory store, fixed dev secret.
Common Mistakes
- Resolving
AuthenticatorProtocol— exported but never bound; useAuthenticationServiceorAuthProviderProtocol - Reading
verified.claims—VerifiedTokenhas typed fields (user_id,roles,permissions,expires_at) - Calling
svc.authenticate(...)— the method isauthenticate_user(email, password) - Storing JWT secrets in code — use
$env-var references; HS256 needs ≥ 32 bytes - Using sync password hashing in async handlers — blocks the event loop
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

