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
- 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 token = client.request_token.await?;
Verifying a Token
// Verify the token
let subject = "example-user".to_string;
let resource = "example-resource".to_string;
let result = client.verify_token.await?;
Getting the Public Key
// 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?;
HTTP/3 Support
To use HTTP/3, enable the http3 feature in your Cargo.toml:
[]
= { = "0.1.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.