Tool to manage authentication and identity

Constructors

  • Parameters

    • _identity: types.Identity | PartialIdentity
    • _key: utils.agent.SignIdentity | PartialIdentity
    • _chain: null | DelegationChain
    • _storage: AuthClientStorage
    • idleManager: undefined | IdleManager
    • _createOptions: undefined | AuthClientCreateOptions
    • Optional _idpWindow: Window
    • Optional _eventHandler: ((event) => void)

    Returns types.AuthClient

Properties

_identity: any
_key: any
_chain: any
_storage: any
idleManager: undefined | IdleManager
_createOptions: any
_idpWindow?: any
_eventHandler?: any
_registerDefaultIdleCallback: any
_handleSuccess: any
_getEventHandler: any
_handleFailure: any
_removeEventListener: any

Methods

  • Create an AuthClient to manage authentication and identity

    Parameters

    • Optional options: {
          identity?: utils.agent.SignIdentity | PartialIdentity;
          storage?: AuthClientStorage;
          keyType?: BaseKeyType;
          idleOptions?: IdleOptions;
      }

      Options for creating an AuthClient

      • Optional identity?: utils.agent.SignIdentity | PartialIdentity

        An SignIdentity or PartialIdentity to authenticate via delegation.

      • Optional storage?: AuthClientStorage

        AuthClientStorage

        Description

        Optional storage with get, set, and remove. Uses IdbStorage by default

      • Optional keyType?: BaseKeyType

        type to use for the base key

        Default

        'ECDSA'
        If you are using a custom storage provider that does not support CryptoKey storage,
        you should use 'Ed25519' as the key type, as it can serialize to a string
      • Optional idleOptions?: IdleOptions

        Options to handle idle timeouts

        Default

        after 10 minutes, invalidates the identity
        

    Returns Promise<types.AuthClient>

    Constructs

    See

    • AuthClientCreateOptions
    • SignIdentity
    • AuthClientStorage
    • IdleOptions Default behavior is to clear stored identity and reload the page when a user goes idle, unless you set the disableDefaultIdleCallback flag or pass in a custom idle callback.

    Example

    const authClient = await AuthClient.create({
    idleOptions: {
    disableIdle: true
    }
    })
  • Returns Promise<boolean>

  • AuthClient Login - Opens up a new window to authenticate with Internet Identity

    Parameters

    Returns Promise<void>

    Example

    const authClient = await AuthClient.create();
    authClient.login({
    identityProvider: 'http://<canisterID>.127.0.0.1:8000',
    maxTimeToLive: BigInt (7) * BigInt(24) * BigInt(3_600_000_000_000), // 1 week
    windowOpenerFeatures: "toolbar=0,location=0,menubar=0,width=500,height=500,left=100,top=100",
    onSuccess: () => {
    console.log('Login Successful!');
    },
    onError: (error) => {
    console.error('Login Failed: ', error);
    }
    });
  • Parameters

    • Optional options: {
          returnTo?: string;
      }
      • Optional returnTo?: string

    Returns Promise<void>