authkestra-actix
Actix-web integration for authkestra.
This crate provides Actix-web specific extractors and utilities to integrate the authkestra authentication framework into Actix applications.
Features
- Extractors: Easily access validated sessions or JWT claims in your request handlers.
- OAuth2 Helpers: Streamlined functions for initiating login, handling callbacks, and logging out.
- Session Management: Integration with
authkestra-sessionfor server-side session storage.
Usage
Add this to your Cargo.toml:
[]
= "0.1.2"
= "0.1.1"
= "0.1.2"
= "4"
Extractors
AuthSession
Extracts a validated session from a cookie. Requires Arc<dyn SessionStore> and SessionConfig to be registered in app_data.
use AuthSession;
use ;
async
AuthToken
Extracts and validates a JWT from the Authorization: Bearer <token> header. Requires Arc<TokenManager> to be registered in app_data.
use AuthToken;
use ;
async
Jwt<T> (Offline Validation)
Extracts and validates a JWT against a remote JWKS (e.g., Google, Auth0). Requires Arc<JwksCache> and jsonwebtoken::Validation to be registered in app_data.
use Jwt;
use JwksCache;
use ;
use Deserialize;
use Arc;
async
OAuth2 Helpers
The crate provides helpers to manage the OAuth2 flow lifecycle.
SPA vs Server-Side Rendering
For SPA (Single Page Application) use cases where you want to receive a JWT on the frontend:
- The
redirect_uriin your OAuth provider configuration should point to a frontend route (e.g.,https://myapp.com/callback). - Your frontend route should extract the
codeandstatefrom the URL. - The frontend then performs a POST (or GET) request to your backend's callback endpoint (e.g.,
/api/auth/callback) with these parameters. - The backend uses
handle_oauth_callback_jwtto exchange the code for a JWT and returns it to the frontend.
use ;
use ;
use Arc;
// 1. Initiate Login
async
// 2. Handle Callback (Server-Side Session)
async
// 3. Logout
async
Setup
To use the extractors and helpers, you must configure your Actix app with the necessary data:
use ;
use SessionConfig;
use MemoryStore;
use TokenManager;
use Arc;
async
Part of authkestra
This crate is part of the authkestra workspace.