Skip to main content

AuthorizationVerifier

Struct AuthorizationVerifier 

Source
pub struct AuthorizationVerifier { /* private fields */ }
Expand description

Builder for verifying Hessra authorization tokens with flexible configuration.

This builder allows you to configure various verification parameters including optional domain restrictions and service chain attestation.

§Example

use hessra_token_authz::{AuthorizationVerifier, ServiceNode, create_token};
use hessra_token_core::KeyPair;

// Create a token
let keypair = KeyPair::new();
let public_key = keypair.public();
let token = create_token(
    "user123".to_string(),
    "resource456".to_string(),
    "read".to_string(),
    keypair,
)?;

// Basic authorization verification
AuthorizationVerifier::new(
    token.clone(),
    public_key,
    "user123".to_string(),
    "resource456".to_string(),
    "read".to_string(),
)
.verify()?;

// With domain restriction
AuthorizationVerifier::new(
    token.clone(),
    public_key,
    "user123".to_string(),
    "resource456".to_string(),
    "read".to_string(),
)
.with_domain("example.com".to_string())
.verify()?;

// With service chain attestation
let service_nodes = vec![
    ServiceNode {
        component: "api-gateway".to_string(),
        public_key: "ed25519/abcd1234...".to_string(),
    }
];
AuthorizationVerifier::new(
    token,
    public_key,
    "user123".to_string(),
    "resource456".to_string(),
    "read".to_string(),
)
.with_service_chain(service_nodes, Some("api-gateway".to_string()))
.verify()?;

Implementations§

Source§

impl AuthorizationVerifier

Source

pub fn new( token: String, public_key: PublicKey, subject: String, resource: String, operation: String, ) -> AuthorizationVerifier

Creates a new authorization verifier for a base64-encoded token.

§Arguments
  • token - The base64-encoded authorization token to verify
  • public_key - The public key used to verify the token signature
  • subject - The subject (user) identifier to verify authorization for
  • resource - The resource identifier to verify authorization against
  • operation - The operation to verify authorization for
Source

pub fn from_bytes( token: Vec<u8>, public_key: PublicKey, subject: String, resource: String, operation: String, ) -> Result<AuthorizationVerifier, TokenError>

Creates a new authorization verifier from raw token bytes.

§Arguments
  • token - The raw binary Biscuit token bytes
  • public_key - The public key used to verify the token signature
  • subject - The subject (user) identifier to verify authorization for
  • resource - The resource identifier to verify authorization against
  • operation - The operation to verify authorization for
Source

pub fn new_capability( token: String, public_key: PublicKey, resource: String, operation: String, ) -> AuthorizationVerifier

Creates a new capability-based verifier (no subject required).

This verifier will accept any token that grants the specified capability (resource + operation), regardless of the subject. The subject is derived from the token’s rights instead of being provided explicitly.

§Arguments
  • token - The base64-encoded authorization token to verify
  • public_key - The public key used to verify the token signature
  • resource - The resource identifier to verify authorization against
  • operation - The operation to verify authorization for
Source

pub fn from_bytes_capability( token: Vec<u8>, public_key: PublicKey, resource: String, operation: String, ) -> Result<AuthorizationVerifier, TokenError>

Creates a new capability-based verifier from raw token bytes.

This is the binary token version of new_capability. It accepts any token that grants the specified capability (resource + operation), regardless of the subject.

§Arguments
  • token - The raw binary Biscuit token bytes
  • public_key - The public key used to verify the token signature
  • resource - The resource identifier to verify authorization against
  • operation - The operation to verify authorization for
Source

pub fn with_domain(self, domain: String) -> AuthorizationVerifier

Adds a domain restriction to the verification.

When set, adds a domain fact to the authorizer. This is required for verifying domain-restricted tokens.

§Arguments
  • domain - The domain to verify against (e.g., “example.com”)
Source

pub fn with_prefix(self, prefix: String) -> AuthorizationVerifier

Adds a prefix restriction to the verification.

When set, adds a prefix fact to the authorizer. This is required for verifying prefix-restricted tokens.

§Arguments
  • prefix - The prefix to verify against (e.g., “tenant/TENANTID/user/USERID/”)
Source

pub fn with_service_chain( self, service_nodes: Vec<ServiceNode>, component: Option<String>, ) -> AuthorizationVerifier

Adds service chain attestation verification.

When set, verifies that the token has been properly attested by the specified service chain nodes.

§Arguments
  • service_nodes - The list of service nodes in the chain
  • component - Optional specific component to verify in the chain
Source

pub fn verify(self) -> Result<(), TokenError>

Performs the token verification with the configured parameters.

§Returns
  • Ok(()) - If the token is valid and meets all verification requirements
  • Err(TokenError) - If verification fails for any reason
§Errors

Returns an error if:

  • The token is malformed or cannot be parsed
  • The token signature is invalid
  • The token has expired
  • The token does not grant the required access rights
  • The domain doesn’t match (if domain restriction is set on token)
  • Service chain attestation fails (if service chain is configured)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more