pub trait Authenticator:
Send
+ Sync
+ 'static {
// Required method
fn authenticate(
&self,
creds: &ClientCredentials,
) -> impl Future<Output = Result<Principal, AuthError>> + Send;
}Expand description
Authenticates a client and returns the principal. mTLS and/or token.
Consumed through generics (no dyn on the hot path); the future must be Send.
§Examples
use osproxy_core::PrincipalId;
use osproxy_spi::{Authenticator, AuthError, ClientCredentials, Principal};
struct AllowAnyToken;
impl Authenticator for AllowAnyToken {
async fn authenticate(&self, creds: &ClientCredentials) -> Result<Principal, AuthError> {
let token = creds.bearer_token.as_deref().ok_or(AuthError::MissingCredentials)?;
Ok(Principal::new(PrincipalId::from(token)))
}
}Required Methods§
Sourcefn authenticate(
&self,
creds: &ClientCredentials,
) -> impl Future<Output = Result<Principal, AuthError>> + Send
fn authenticate( &self, creds: &ClientCredentials, ) -> impl Future<Output = Result<Principal, AuthError>> + Send
Authenticates the credentials, returning the principal.
§Errors
Returns AuthError::MissingCredentials or AuthError::InvalidCredentials.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".