auth_resolver/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct AuthContext {
    pub initiator: String,
    pub system:    String,
}

#[derive(Debug)]
pub struct AuthResolverError {
    err: String,
}

impl AuthResolverError {
    pub fn new(err: String) -> Self { Self { err } }
}

impl std::fmt::Display for AuthResolverError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.err) }
}

impl std::error::Error for AuthResolverError {}

impl warp::reject::Reject for AuthResolverError {}

#[async_trait::async_trait]
pub trait AuthResolver {
    async fn authenticate(&self, headers: warp::http::HeaderMap) -> Result<AuthContext, AuthResolverError>;
}