use std::collections::BTreeMap;
use axess_identity::{HumanPrincipal, IdentityError, Principal, PrincipalResolver};
use crate::AuthSession;
#[derive(Clone)]
pub struct SessionResolver {
session: AuthSession,
}
impl SessionResolver {
pub fn new(session: AuthSession) -> Self {
Self { session }
}
}
impl PrincipalResolver for SessionResolver {
async fn resolve(&self) -> Result<Principal, IdentityError> {
let snap = self
.session
.snapshot()
.await
.ok_or(IdentityError::NotAuthenticated)?;
Ok(Principal::Human(HumanPrincipal {
user_id: snap.user_id,
tenant_id: snap.tenant_id,
session_id: Some(snap.session_id),
attributes: BTreeMap::new(),
}))
}
}