Hessra API
HTTP client for Hessra authentication services.
This crate provides a client for making HTTP requests to the Hessra authorization service. It supports both HTTP/1.1 and HTTP/3 (as an optional feature) and implements the OpenAPI specification for the Hessra service.
Features
- HTTP/1.1 client for Hessra services
- Optional HTTP/3 support via the
http3feature flag - Implementation of all Hessra API endpoints including multi-party authorization
- Multi-party token signing via the
/sign_tokenendpoint - Mutual TLS (mTLS) for secure client authentication
- Proper error handling with custom error types
- Comprehensive test coverage
Usage
Creating a Client
use HessraClient;
use HessraConfig;
// Load configuration from environment variables
let config = from_env?;
// Create a client using the configuration
let client = builder
.from_config
.build?;
// Or create a client manually
let client = builder
.base_url
.port
.protocol
.mtls_cert
.mtls_key
.server_ca
.public_key
.personal_keypair
.build?;
Requesting a Token
// Request a token for a resource
let resource = "example-resource".to_string;
let operation = "read".to_string;
let token = client.request_token.await?;
Verifying a Token
// Verify the token
let subject = "example-user".to_string;
let resource = "example-resource".to_string;
let operation = "read".to_string;
let result = client.verify_token.await?;
Getting the Public Key
The public_key endpoint is available for both authenticated and unauthenticated requests. If requesting the public_key with an authenticated request and authentication fails, the request will fail.
// Retrieve the server's public key
let public_key = client.get_public_key.await?;
// Or fetch the public key without creating a client
let public_key = fetch_public_key.await?;
Verifying a Service Chain Token
// Verify a service chain token
let result = client.verify_service_chain_token.await?;
Multi-Party Token Signing
Sign a token that requires multi-party authorization:
// Sign a token using the /sign_token endpoint
let signed_response = client.sign_token.await?;
if let Some = signed_response.token else if let Some = signed_response.pending_signoffs
HTTP/3 Support
To use HTTP/3, enable the http3 feature in your Cargo.toml:
[]
= { = "0.4.0", = ["http3"] }
Then create a client with the HTTP/3 protocol:
let client = builder
.protocol
// ... other configuration
.build?;
Error Handling
The API client provides a custom error type ApiError that includes detailed information about any errors that occur. Errors are categorized into specific types such as HTTP client errors, SSL configuration errors, token request errors, etc.
match client.request_token.await
Examples
See the examples directory for complete usage examples:
client_example.rs: Basic usage of the HTTP/1.1 clienthttp3_example.rs: Using the HTTP/3 client (requires thehttp3feature)
Integration with hessra-config
This crate is designed to work seamlessly with the hessra-config crate, which provides configuration management for Hessra services. You can create a client directly from a HessraConfig instance, which makes it easy to share configuration between multiple components.