Struct Principal
#[non_exhaustive]pub struct Principal {
pub id: PrincipalId,
pub user_id: String,
pub roles: Vec<String>,
pub scopes: Vec<String>,
pub auth_method: AuthMethod,
pub mfa_verified: bool,
pub expires_at: u64,
pub allowed_aliases: Vec<AgentAlias>,
}Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: PrincipalId§user_id: StringHuman/account identifier from the identity source (e.g. OIDC sub).
Equals id.0 for a real user; sentinel for AuthMethod::SharedOperator.
roles: Vec<String>Coarse roles the identity source asserted (drives IamPolicy mapping).
scopes: Vec<String>Fine-grained scopes/capabilities granted this session.
auth_method: AuthMethodHow this principal authenticated.
mfa_verified: boolWhether a second factor was completed (drives any step-up policy).
expires_at: u64Session expiry, UNIX seconds; 0 = no expiry.
allowed_aliases: Vec<AgentAlias>Agent aliases this principal MAY bind at session/new. Empty + no roles ⇒
the AuthMethod::SharedOperator fallback (“any configured alias”,
today’s behaviour).
Implementations§
Source§impl Principal
impl Principal
Sourcepub fn new(
id: impl Into<PrincipalId>,
user_id: impl Into<String>,
auth_method: AuthMethod,
) -> Self
pub fn new( id: impl Into<PrincipalId>, user_id: impl Into<String>, auth_method: AuthMethod, ) -> Self
Construct an authenticated principal with the given subject id and method.
Grants default to empty; attach claims via the with_* builder setters.
This is the construction path other crates (the providers) must use because
the struct is #[non_exhaustive].
Sourcepub fn with_roles(self, roles: Vec<String>) -> Self
pub fn with_roles(self, roles: Vec<String>) -> Self
Attach the role claims the identity source asserted.
Sourcepub fn with_scopes(self, scopes: Vec<String>) -> Self
pub fn with_scopes(self, scopes: Vec<String>) -> Self
Attach the scope claims granted this session.
Sourcepub fn with_mfa_verified(self, mfa_verified: bool) -> Self
pub fn with_mfa_verified(self, mfa_verified: bool) -> Self
Mark MFA as completed.
Sourcepub fn with_expires_at(self, expires_at: u64) -> Self
pub fn with_expires_at(self, expires_at: u64) -> Self
Set the session expiry (UNIX seconds; 0 = none).
Sourcepub fn with_allowed_aliases(self, allowed_aliases: Vec<AgentAlias>) -> Self
pub fn with_allowed_aliases(self, allowed_aliases: Vec<AgentAlias>) -> Self
Attach the agent aliases this principal may bind.
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
true once a distinct identity source authenticated this principal —
i.e. not unbound (AuthMethod::None) and not the shared-operator
sentinel. A2A distinct-principal routing keys on this.