use crate::app_context::AppContext;
use crate::observability::Metrics;
use crate::shared::HttpResult;
use super::cookie::service::CookieAuthService;
use super::{AuthSession, GrantAuthService, RevocationListener};
#[derive(Clone, Debug)]
pub struct AuthState {
pub(crate) grant_auth_service: GrantAuthService,
pub(crate) cookie_auth_service: CookieAuthService,
pub(crate) metrics: Metrics,
pub(crate) revocation_listener: RevocationListener,
}
impl AuthState {
pub fn new(context: &AppContext) -> Self {
Self {
grant_auth_service: GrantAuthService::from_context(context),
cookie_auth_service: CookieAuthService::from_context(context),
metrics: context.metrics.clone(),
revocation_listener: context.revocation_listener.clone(),
}
}
pub(crate) async fn validate_private_stream_session(
&self,
session: &AuthSession,
) -> HttpResult<()> {
match session {
AuthSession::Cookie(cookie) => {
self.cookie_auth_service
.validate_active_session(cookie)
.await
}
AuthSession::Grant(grant) => self
.grant_auth_service
.validate_active_grant_session(grant)
.await
.map(|_| ())
.map_err(Into::into),
}
}
}