use std::sync::Arc;
use super::super::domain::AuthorizeData;
use super::super::domain::CallbackRequestParams;
use super::super::domain::OidcSessionPersisted;
use super::super::ports::authentication_engine::AuthenticationEngine;
use super::error::AuthenticationServiceError;
use crate::user::domain::User;
#[derive(Debug, Clone)]
pub struct AuthenticationService {
authentication_engine: Arc<dyn AuthenticationEngine>,
}
impl AuthenticationService {
pub fn new(authentication_engine: Arc<dyn AuthenticationEngine>) -> Self {
Self {
authentication_engine,
}
}
pub async fn authorize(&self) -> Result<AuthorizeData, AuthenticationServiceError> {
Ok(self.authentication_engine.authorize().await?)
}
pub async fn callback(
&self,
callback_params: CallbackRequestParams,
persisted_data: OidcSessionPersisted,
) -> Result<User, AuthenticationServiceError> {
Ok(self
.authentication_engine
.callback(callback_params, persisted_data)
.await?)
}
}