pub struct ClientBuilder<State> { /* private fields */ }Expand description
Builder for LastIDClient with type-state pattern.
§Type-State Pattern
The builder enforces that configuration must be provided before building:
ClientBuilder<NoConfig>- Initial state, no configClientBuilder<HasConfig>- Config provided, can build
§Example
use lastid_sdk::ClientBuilder;
// Auto-discover configuration
let client = ClientBuilder::new().with_auto_config()?.build()?;
// Or use explicit configuration
use lastid_sdk::SDKConfig;
let config = SDKConfig::builder()
.idp_endpoint("https://human.lastid.co")
.build()?;
let client = ClientBuilder::new().with_config(config).build()?;§Serverless Keypair Persistence
For serverless deployments, see
with_keypair to restore a persisted DPoP
keypair across invocations.
Implementations§
Source§impl ClientBuilder<NoConfig>
impl ClientBuilder<NoConfig>
Sourcepub fn with_auto_config(self) -> Result<ClientBuilder<HasConfig>, LastIDError>
pub fn with_auto_config(self) -> Result<ClientBuilder<HasConfig>, LastIDError>
Auto-discover configuration from filesystem and environment.
Searches for TOML files in standard locations:
./lastid.toml(current directory)~/.config/lastid/config.toml(user config)/etc/lastid/config.toml(system config, Unix only)
Environment variables override file-based configuration.
§Errors
Returns LastIDError::Config if no configuration is found.
Sourcepub fn with_config(self, config: SDKConfig) -> ClientBuilder<HasConfig>
pub fn with_config(self, config: SDKConfig) -> ClientBuilder<HasConfig>
Use an explicit configuration.
Sourcepub fn with_toml_file(
self,
path: &Path,
) -> Result<ClientBuilder<HasConfig>, LastIDError>
pub fn with_toml_file( self, path: &Path, ) -> Result<ClientBuilder<HasConfig>, LastIDError>
Load configuration from a TOML file.
§Note
This method is only available on native platforms (not WASM).
In WASM, use with_config or store config in
localStorage.
§Errors
Returns LastIDError::Config if the file cannot be read or parsed.
Source§impl ClientBuilder<HasConfig>
impl ClientBuilder<HasConfig>
Sourcepub fn with_keypair(self, keypair: DPoPKeyPair) -> Self
pub fn with_keypair(self, keypair: DPoPKeyPair) -> Self
Use a pre-generated or restored DPoP keypair.
This is useful for serverless deployments where the keypair needs to be persisted across invocations. The keypair can be serialized to JSON and stored in a secrets manager, then deserialized and passed to this method.
§Security
The keypair contains the private key. Ensure it is stored encrypted at
rest (e.g., AWS Secrets Manager, HashiCorp Vault, encrypted
environment variables).
§Example
Using a generated keypair:
use lastid_sdk::crypto::DPoPKeyPair;
use lastid_sdk::{ClientBuilder, SDKConfig};
let keypair = DPoPKeyPair::generate()?;
let config = SDKConfig::builder()
.idp_endpoint("https://human.lastid.co")
.client_id("my-app")
.build()?;
let client = ClientBuilder::new()
.with_config(config)
.with_keypair(keypair)
.build()?;Serializing and restoring a keypair (requires keypair-serialization
feature):
use lastid_sdk::{ClientBuilder, SDKConfig};
use lastid_sdk::crypto::DPoPKeyPair;
// Generate and serialize a keypair for initial deployment
let keypair = DPoPKeyPair::generate()?;
let serialized = serde_json::to_string(&keypair).unwrap();
// Store `serialized` in your secrets manager...
// Later, in a serverless function cold start:
let restored: DPoPKeyPair = serde_json::from_str(&serialized).unwrap();
let config = SDKConfig::builder()
.idp_endpoint("https://human.lastid.co")
.client_id("my-app")
.build()?;
let client = ClientBuilder::new()
.with_config(config)
.with_keypair(restored)
.build()?;Sourcepub fn build(self) -> Result<LastIDClient, LastIDError>
pub fn build(self) -> Result<LastIDClient, LastIDError>
Build the client.
§Errors
Returns LastIDError if:
- Configuration validation fails
- HTTP client creation fails
DPoPkey initialization fails