backbone_auth/
middleware.rs1use anyhow::Result;
4use async_trait::async_trait;
5
6#[async_trait]
8pub trait AuthMiddleware {
9 async fn authenticate(&self, token: &str) -> Result<AuthContext>;
10}
11
12#[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#[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}