Skip to main content

backbone_auth/
middleware.rs

1//! Authentication middleware
2
3use anyhow::Result;
4use async_trait::async_trait;
5
6/// Authentication middleware trait
7#[async_trait]
8pub trait AuthMiddleware {
9    async fn authenticate(&self, token: &str) -> Result<AuthContext>;
10}
11
12/// Trait for extracting authentication information from requests
13#[async_trait]
14pub trait AuthExtractor {
15    async fn extract_token(&self) -> Result<Option<String>>;
16    async fn extract_user_context(&self) -> Result<Option<AuthContext>>;
17}
18
19/// Authentication context
20#[derive(Debug, Clone)]
21pub struct AuthContext {
22    pub user_id: String,
23    pub roles: Vec<String>,
24    pub permissions: Vec<String>,
25}
26
27impl AuthContext {
28    pub fn new(user_id: String) -> Self {
29        Self {
30            user_id,
31            roles: Vec::new(),
32            permissions: Vec::new(),
33        }
34    }
35}