#internet-computer #identity #front-end #icp #web-apps #web-api #api-bindings

ic-auth-client

A client library for Internet Computer identity authentication services

5 unstable releases

new 0.3.1 Nov 14, 2024
0.3.0 Nov 11, 2024
0.2.1 Sep 24, 2024
0.1.1 Aug 24, 2024
0.0.1 Aug 24, 2024

#323 in Authentication

Download history 257/week @ 2024-08-19 29/week @ 2024-08-26 162/week @ 2024-09-09 22/week @ 2024-09-16 210/week @ 2024-09-23 15/week @ 2024-09-30 4/week @ 2024-10-07 3/week @ 2024-10-14 243/week @ 2024-11-11

243 downloads per month

Apache-2.0

72KB
1.5K SLoC

ic-auth-client

Port of @dfinity/auth-client for the Rust programming language.

This is a crate for developers who build the frontend of applications for Internet Computer using Rust as the primary language within a Web browser or Webview environment.

If you use JavaScript for frontend, you can use the Internet Identity Service compatible libraries such as @dfinity/auth-client or @nfid/identitykit.

For native Rust frontend that does not have access to Browser APIs, this crate cannot be used, but you may create your own implementation by referring to the structs included in the code.

Version compatibility for ic-agent

The table below shows the compatible versions of ic-auth-client for ic-agent versions.

ic-agent version ic-auth-client version
0.39.* 0.3.*
0.37.* or 0.38.* 0.1.* or 0.2.*

Quick Start

In the browser:

use ic_auth_client::AuthClient;

To get started with auth client, run

let mut auth_client = AuthClient::builder()
    // any configurations
    .build()
    .await;

The auth_client can log in with

use ic_auth_client::AuthClientLoginOptions;

let options = AuthClientLoginOptions::builder()
    .max_time_to_live(7 * 24 * 60 * 60 * 1000 * 1000 * 1000)
    .on_success(|auth_success| {
        // handle success
    })
    .build();

auth_client.login_with_options(options);

It opens an identity.ic0.app window, saves your delegation to localStorage, and then sets you up with an identity.

Then, you can use that identity to make authenticated calls using the ic-agent::Agent.

let identity = auth_client.identity();

let agent = Agent::builder()
    .with_url(url)
    .with_identity(identity)
    .build()?;

Dependencies

~22–34MB
~551K SLoC