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 AuthenticationProvider: Send + Sync + 'static {
14 async fn configure(
16 &self,
17 _name: &str,
18 _config: serde_json::Map<String, serde_json::Value>,
19 ) -> Result<()> {
20 Ok(())
21 }
22
23 fn metadata(&self) -> Option<RuntimeMetadata> {
25 None
26 }
27
28 fn warnings(&self) -> Vec<String> {
30 Vec::new()
31 }
32
33 async fn health_check(&self) -> Result<()> {
35 Ok(())
36 }
37
38 async fn start(&self) -> Result<()> {
40 Ok(())
41 }
42
43 async fn close(&self) -> Result<()> {
45 Ok(())
46 }
47
48 async fn begin_login(&self, req: BeginLoginRequest) -> Result<BeginLoginResponse>;
50
51 async fn complete_login(&self, req: CompleteLoginRequest) -> Result<AuthenticatedUser>;
53
54 async fn validate_external_token(&self, _token: &str) -> Result<Option<AuthenticatedUser>> {
56 Err(Error::unimplemented(
57 "authentication provider does not support external token validation",
58 ))
59 }
60
61 fn session_ttl(&self) -> Option<Duration> {
63 None
64 }
65}