Hessra SDK
The primary interface for interacting with Hessra authentication services.
API Reference
This crate integrates functionality from these component crates:
hessra-token: Token verification and attestationhessra-config: Configuration managementhessra-api: HTTP client for the Hessra service
Detailed Usage
Creating a Client
use ;
// Basic client setup
let client = builder
.base_url
.protocol
.build?;
// More complete setup with mTLS certificates
let mut secure_client = builder
.base_url
.protocol
.mtls_cert
.mtls_key
.server_ca
.build?;
// Finishes setting up the client by making API calls to the Hessra
// service for its token signing public key
secure_client.setup?;
// Loading from environment variables
// keys and certs should be base64 encoded PEM
let env_client = from_env?;
// Loading from a configuration file
let file_client = from_file?;
Working with Tokens
The authorization service requires a client to authenticate itself in order to get a token for it to use for a given operation on a resource. Currently, that means using an mTLS connection where the client/subject identifier is encoded in an x509 client certificate as a Subject Alternative Name (SAN).
// Request a token
let subject = "user:123";
let resource = "resource1";
let operation = "read";
let token = client.request_token.await?;
println!;
// Simple token verification. Tries locally then fallsback to service API
let verification = client.verify_token.await?;
println!;
// Local token verification (using cached public keys)
let local_verification = client.verify_token_local?;
println!;
Advanced: Service Chain Authorization
For services that need to verify tokens passed through multiple services:
use ;
// gateway-service adds attestation
gateway_token = gateway_client.attest_service_chain_token;
// processing-service adds attestation
processing_token = processing_client.attest_service_chain_token;
// Define the service chain (order matters!)
let service_chain = builder
.add_node
.add_node
.build;
// Verify a token with the service chain
// This token is only valid if it has visited and been attested by
// the gateway-service and processing-service.
client.verify_service_chain_token.await?;
// Local verification of service chain token
client.verify_service_chain_token_local?;
Error Handling
The SDK provides a comprehensive error handling system:
use HessraError;
Feature Flags
Note: http3 support is currently unstable since it relies on reqwest's implementation which is also unstable. Once reqwest's http3 is stable, it will be here too.
WASM support is currently a WIP. Please open an issue if you need WASM or the ability for offline token verification in javascript/typescript.
toml: Enables TOML configuration file support via thehessra-configcratehttp3: Enables HTTP/3 protocol support via thehessra-apicratewasm: Enables WebAssembly support for token verification via thehessra-tokencrate
Using HTTP/3
When the http3 feature is enabled:
use ;
let client = builder
.base_url
.protocol
.build?;
requires building with RUSTFLAGS='--cfg reqwest_unstable'
Once reqwest http3 support is stable, this won't be necessary.
License
Licensed under the Apache License, Version 2.0.