Crate libauth_rs

Crate libauth_rs 

Source
Expand description

§libauth-rs

A unified authentication and authorization library with support for multiple providers:

  • Clerk (feature: clerk)
  • Stytch (feature: stytch)
  • Microsoft Azure AD / MSAL (feature: msal)

§Features

  • Feature-gated providers: Only include the authentication providers you need
  • Axum middleware: Drop-in authentication middleware for Axum web applications
  • Type-safe: Strongly typed authentication and authorization primitives
  • Async-first: Built on async/await for high performance

§Quick Start

[dependencies]
libauth-rs = { version = "0.1", features = ["clerk", "axum"] }
use libauth_rs::providers::{AuthConfig, ClerkProvider};
use libauth_rs::middleware::AuthLayer;
use axum::{Router, routing::get};

#[tokio::main]
async fn main() {
    let config = AuthConfig::default();
    let clerk = ClerkProvider::new(&config).await.unwrap();

    let auth_layer = AuthLayer::new(vec![Box::new(clerk)]);

    let app = Router::new()
        .route("/", get(|| async { "Hello, World!" }))
        .layer(auth_layer);

    // Run your server...
}

Re-exports§

pub use error::AuthError;
pub use error::AuthResult;
pub use traits::ClientAccess;
pub use types::AuthProvider;
pub use types::AuthToken;
pub use types::TokenType;
pub use types::UserContext;
pub use traits::Authn as AuthProviderTrait;
pub use middleware::AuthContext;
pub use middleware::AuthExtension;
pub use middleware::AuthLayer;
pub use middleware::AuthMiddleware;
pub use middleware::OptionalAuth;

Modules§

error
middleware
prelude
Prelude module for convenient imports
traits
types
vendor

Structs§

StytchProvider
Stytch B2B Session Provider

Enums§

Config
Modern, type-safe configuration for authentication providers

Constants§

VERSION
Library version