use std::fmt::Debug;
use async_trait::async_trait;
use super::super::domain::AuthorizeData;
use super::super::domain::CallbackRequestParams;
use super::super::domain::OidcSessionPersisted;
use crate::user::domain::User;
#[async_trait]
#[cfg_attr(test, mockall::automock)]
pub trait AuthenticationEngine: Debug + Send + Sync + 'static {
async fn authorize(&self) -> Result<AuthorizeData, AuthenticationEngineError>;
async fn callback(
&self,
callback_params: CallbackRequestParams,
persisted_data: OidcSessionPersisted,
) -> Result<User, AuthenticationEngineError>;
}
#[derive(Debug, Clone, thiserror::Error)]
pub enum AuthenticationEngineError {
#[error("unable to set up infrastructure: {message}")]
Infrastructure { message: String },
#[error("unable exchange information with the IdP: {message}")]
IdpExchange { message: String },
#[error("unable to validate IdP data: {message}")]
Validation { message: String },
}