Skip to main content

ClientBuilder

Struct ClientBuilder 

Source
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 config
  • ClientBuilder<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>

Source

pub const fn new() -> Self

Create a new client builder.

Source

pub fn with_auto_config(self) -> Result<ClientBuilder<HasConfig>, LastIDError>

Auto-discover configuration from filesystem and environment.

Searches for TOML files in standard locations:

  1. ./lastid.toml (current directory)
  2. ~/.config/lastid/config.toml (user config)
  3. /etc/lastid/config.toml (system config, Unix only)

Environment variables override file-based configuration.

§Errors

Returns LastIDError::Config if no configuration is found.

Source

pub fn with_config(self, config: SDKConfig) -> ClientBuilder<HasConfig>

Use an explicit configuration.

Source

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>

Source

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()?;
Source

pub fn build(self) -> Result<LastIDClient, LastIDError>

Build the client.

§Errors

Returns LastIDError if:

  • Configuration validation fails
  • HTTP client creation fails
  • DPoP key initialization fails

Trait Implementations§

Source§

impl Default for ClientBuilder<NoConfig>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<State> Freeze for ClientBuilder<State>

§

impl<State> RefUnwindSafe for ClientBuilder<State>
where State: RefUnwindSafe,

§

impl<State> Send for ClientBuilder<State>
where State: Send,

§

impl<State> Sync for ClientBuilder<State>
where State: Sync,

§

impl<State> Unpin for ClientBuilder<State>
where State: Unpin,

§

impl<State> UnsafeUnpin for ClientBuilder<State>

§

impl<State> UnwindSafe for ClientBuilder<State>
where State: UnwindSafe,

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