Integration — Aquilia Documentation
Comprehensive guide and documentation for Integration in the Aquilia framework. View API reference, examples, and implementation patterns.
Security & Auth Integration & Middleware The aquilia.auth.integration package wires authentication seamlessly into Aquilia's dependency injection container, request-response middleware pipelines, session subsystems, and flow graphs. Integration Components , , , , ].map((s, i) => ( ))} DI Providers Importing aquilia.auth.integration.di_providers exposes all auth services to the DI registry under @service(scope="app"). from aquilia.auth.integration.di_providers import * # Provider → Provides # ───────────────────────────────────────── # PasswordHasherProvider → PasswordHasher (Argon2id) # KeyRingProvider → KeyRing (auto-generates RS256 key) # TokenManagerProvider → TokenManager (15m access, 30d refresh) # RateLimiterProvider → RateLimiter (5 attempts, 15min lockout) # MemoryIdentityStoreProvider → IdentityStore (in-memory) # MemoryCredentialStoreProvider → CredentialStore (in-memory) # MemoryTokenStoreProvider → TokenStore (in-memory) # MemoryOAuthClientStoreProvider → OAuthClientStore (in-memory) # MemoryAuthCodeStoreProvider → AuthorizationCodeStore (in-memory) # MemoryDeviceCodeStoreProvider → DeviceCodeStore (in-memory) # AuthManagerProvider → AuthManager (full auth pipeline) # MFAManagerProvider → MFAManager (TOTP + backup codes) # OAuth2ManagerProvider → OAuth2Manager (all 4 grant types) # AuthzEngineProvider → AuthzEngine (RBAC + ABAC + scopes) # SessionEngineProvider → SessionEngine (auth sessions) # SessionAuthBridgeProvider → SessionAuthBridge (session ↔ auth) Customizing Providers Override standard providers in the container context. Dependent services like AuthManager resolve overrides automatically. from aquilia.di import Container container = Container() # Register custom database/cache storage implementations container.register(IdentityStore, MyDatabaseIdentityStore) container.register(TokenStore, RedisTokenStore(redis_client)) # Other default providers dynamically resolve with the overrides Auth Middleware Pipeline The AuthMiddleware performs request authentication sequentially in 6 structured phases: , , , , , , ].map((step, i) => ( ))} from aquilia.auth.middleware import AuthMiddleware app = Aquilia() # Main authentication middleware configured with pluggable backends app.use(AuthMiddleware( auth_manager=auth_manager, session_engine=session_engine, require_auth=False, # Opt-in manually using decorators backends=[ "aquilia.auth.backends.TokenBackend", "aquilia.auth.backends.SessionBackend", ] )) Flow Graph Integration Because the new stateless guards in aquilia.auth.guards implement the callable protocol (__call__), they can be inserted directly as nodes inside Aquilia flow pipelines without any adapters. Flow Graph Assembly from aquilia.flow import Flow from aquilia.auth.guards import AuthGuard, RoleGuard admin_flow = ( Flow("admin_pipeline") .then(AuthGuard()) .then(RoleGuard("admin")) .then(execute_admin_logic_node) ) AuthPrincipal & Session Bridge Extract user parameters, roles, and scope permissions dynamically from current session contexts: from aquilia.auth.integration.aquila_sessions import ( bind_identity, bind_token_claims, get_identity_id, get_roles, get_scopes, ) # Set bindings (executed during request intercept) bind_identity(session, identity) bind_token_claims(session, claims) # Resolve attributes inside handler user_id = get_identity_id(session) roles = get_roles(session) scopes = get_scopes(session) )
Go to Homepage