Skip to main content

gestalt/
auth.rs

1use std::time::Duration;
2
3use tonic::codegen::async_trait;
4
5use crate::api::RuntimeMetadata;
6use crate::error::{Error, Result};
7pub use crate::generated::v1::{
8    AuthenticatedUser, BeginLoginRequest, BeginLoginResponse, CompleteLoginRequest,
9};
10
11#[async_trait]
12pub trait AuthProvider: Send + Sync + 'static {
13    async fn configure(
14        &self,
15        _name: &str,
16        _config: serde_json::Map<String, serde_json::Value>,
17    ) -> Result<()> {
18        Ok(())
19    }
20
21    fn metadata(&self) -> Option<RuntimeMetadata> {
22        None
23    }
24
25    fn warnings(&self) -> Vec<String> {
26        Vec::new()
27    }
28
29    async fn health_check(&self) -> Result<()> {
30        Ok(())
31    }
32
33    async fn close(&self) -> Result<()> {
34        Ok(())
35    }
36
37    async fn begin_login(&self, req: BeginLoginRequest) -> Result<BeginLoginResponse>;
38
39    async fn complete_login(&self, req: CompleteLoginRequest) -> Result<AuthenticatedUser>;
40
41    async fn validate_external_token(&self, _token: &str) -> Result<Option<AuthenticatedUser>> {
42        Err(Error::unimplemented(
43            "auth provider does not support external token validation",
44        ))
45    }
46
47    fn session_ttl(&self) -> Option<Duration> {
48        None
49    }
50}