ic-reactor
    Preparing search index...

    Class AuthClient

    Tool to manage authentication and identity

    Index

    Constructors

    • Parameters

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

      Returns types.AuthClient

    Properties

    idleManager: undefined | IdleManager

    Methods

    • Create an AuthClient to manage authentication and identity

      Parameters

      • Optionaloptions: AuthClientCreateOptions

        Options for creating an AuthClient

        • identity

          Optional Identity to use as the base

        • storage

          Storage mechanism for delegation credentials

        • keyType

          Type of key to use for the base key

        • idleOptions

          Configures an IdleManager

      Returns Promise<types.AuthClient>

      • 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.
      const authClient = await AuthClient.create({
      idleOptions: {
      disableIdle: true
      }
      })
    • Returns Promise<boolean>

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

      Parameters

      • Optionaloptions: types.AuthClientLoginOptions

        Options for logging in, merged with the options set during creation if any. Note: we only perform a shallow merge for the customValues property.

        • OptionalidentityProvider?: string | URL

          Identity provider

          "https://identity.internetcomputer.org"
          
        • OptionalmaxTimeToLive?: bigint

          Expiration of the authentication in nanoseconds

          BigInt(8) hours * BigInt(3_600_000_000_000) nanoseconds
          
        • OptionalallowPinAuthentication?: boolean

          If present, indicates whether or not the Identity Provider should allow the user to authenticate and/or register using a temporary key/PIN identity. Authenticating dapps may want to prevent users from using Temporary keys/PIN identities because Temporary keys/PIN identities are less secure than Passkeys (webauthn credentials) and because Temporary keys/PIN identities generally only live in a browser database (which may get cleared by the browser/OS).

        • OptionalderivationOrigin?: string | URL

          Origin for Identity Provider to use while generating the delegated identity. For II, the derivation origin must authorize this origin by setting a record at <derivation-origin>/.well-known/ii-alternative-origins.

        • OptionalwindowOpenerFeatures?: string

          Auth Window feature config string

          "toolbar=0,location=0,menubar=0,width=500,height=500,left=100,top=100"
          
        • OptionalonSuccess?: OnSuccessFunc

          Callback once login has completed

        • OptionalonError?: OnErrorFunc

          Callback in case authentication fails

        • OptionalcustomValues?: Record<string, unknown>

          Extra values to be passed in the login request during the authorize-ready phase

      Returns Promise<void>

      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

      • Optionaloptions: { returnTo?: string }

      Returns Promise<void>