Module auth

Module auth 

Source
Expand description

Authentication framework for RingKernel.

This module provides a pluggable authentication system with support for multiple methods including API keys, JWT tokens, and OAuth2.

§Feature Flags

  • auth - Enables JWT token validation (requires jsonwebtoken crate)

§Example

use ringkernel_core::auth::{AuthProvider, ApiKeyAuth, AuthContext};

// Simple API key authentication
let auth = ApiKeyAuth::new()
    .add_key("admin", "secret-key-123", &["admin", "read", "write"])
    .add_key("readonly", "readonly-key-456", &["read"]);

let ctx = auth.authenticate(&Credentials::ApiKey("secret-key-123".to_string())).await?;
assert!(ctx.has_permission("write"));

// JWT authentication
let jwt_auth = JwtAuth::new(JwtConfig {
    secret: "your-256-bit-secret".to_string(),
    issuer: Some("ringkernel".to_string()),
    audience: Some("api".to_string()),
    ..Default::default()
});
let ctx = jwt_auth.authenticate(&Credentials::Bearer(token)).await?;

Structs§

ApiKeyAuth
API key authentication provider.
AuthContext
Authentication context for an authenticated request.
ChainedAuthProvider
Authentication provider that tries multiple providers in order.
Identity
Identity of an authenticated principal.

Enums§

AuthError
Error type for authentication operations.
Credentials
Credentials provided by a client for authentication.

Traits§

AuthProvider
Trait for pluggable authentication providers.

Type Aliases§

AuthResult
Result type for authentication operations.