JSPM

  • Created
  • Published
  • Downloads 11928
  • Score
    100M100P100Q144161F
  • License Apache-2.0

JavaScript and TypeScript library to provide a simple integration with an IC Internet Identity

Package Exports

  • @dfinity/auth-client

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@dfinity/auth-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@dfinity/auth-client

Simple interface to get your web application authenticated with the Internet Identity Service

Visit the Dfinity Forum and SDK Documentation for more information and support building on the Internet Computer.

Additional API Documentation can be found here.


Installation

Using AuthClient:

npm i --save @dfinity/auth-client

In the browser:

import * as auth from "@dfinity/auth-client";

or using individual exports:

import { AuthClient } from "@dfinity/auth-client";

To get started with auth client, run

const authClient = await AuthClient.create();

The authClient can log in with

authClient.loginWithRedirect();

It handles redirects, saves your delegation to localStorage, and then sets you up with an identity.

if (location.hash.substring(1).startsWith('access_token')) {
  const identity = await authClient.handleRedirectCallback();
}

Then, you can use that identity to make authenticated calls using the @dfinity/agent Actor.

const actor = Actor.createActor(idlFactory, {
  agent: new HttpAgent({
    host: hostUrlEl.value,
    identity,
  }),
  canisterId,
});

Note: depends on @dfinity/agent, @dfinity/authentication, and @dfinity/identity.