Options
All
  • Public
  • Public/Protected
  • All
Menu

Tool to manage authentication and identity

see

AuthClient

Hierarchy

  • AuthClient

Index

Constructors

  • new AuthClient(_identity: Identity, _key: SignIdentity, _chain: null | DelegationChain, _storage: AuthClientStorage, idleManager: undefined | IdleManager, _createOptions: undefined | AuthClientCreateOptions, _idpWindow?: Window, _eventHandler?: ((event: MessageEvent<any>) => void)): AuthClient
  • Parameters

    • _identity: Identity
    • _key: SignIdentity
    • _chain: null | DelegationChain
    • _storage: AuthClientStorage
    • idleManager: undefined | IdleManager
    • _createOptions: undefined | AuthClientCreateOptions
    • Optional _idpWindow: Window
    • Optional _eventHandler: ((event: MessageEvent<any>) => void)
        • (event: MessageEvent<any>): void
        • Parameters

          • event: MessageEvent<any>

          Returns void

    Returns AuthClient

Properties

idleManager: undefined | IdleManager

Methods

  • _getEventHandler(identityProviderUrl: URL, options?: AuthClientLoginOptions): ((event: MessageEvent<any>) => Promise<void>)
  • Parameters

    Returns ((event: MessageEvent<any>) => Promise<void>)

      • (event: MessageEvent<any>): Promise<void>
      • Parameters

        • event: MessageEvent<any>

        Returns Promise<void>

  • _handleFailure(errorMessage?: string, onError?: ((error?: string) => void)): void
  • Parameters

    • Optional errorMessage: string
    • Optional onError: ((error?: string) => void)
        • (error?: string): void
        • Parameters

          • Optional error: string

          Returns void

    Returns void

  • _handleSuccess(message: InternetIdentityAuthResponseSuccess, onSuccess?: (() => void)): Promise<void>
  • Parameters

    • message: InternetIdentityAuthResponseSuccess
    • Optional onSuccess: (() => void)
        • (): void
        • Returns void

    Returns Promise<void>

  • _removeEventListener(): void
  • getIdentity(): Identity
  • isAuthenticated(): Promise<boolean>
  • login(options?: { derivationOrigin?: string | URL; identityProvider?: string | URL; maxTimeToLive?: bigint; onError?: ((error?: string) => void) | ((error?: string) => Promise<void>); onSuccess?: (() => void) | (() => Promise<void>); windowOpenerFeatures?: string }): Promise<void>
  • AuthClient Login - Opens up a new window to authenticate with Internet Identity

    example

    const authClient = await AuthClient.create(); authClient.login({ identityProvider: 'http://.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: { derivationOrigin?: string | URL; identityProvider?: string | URL; maxTimeToLive?: bigint; onError?: ((error?: string) => void) | ((error?: string) => Promise<void>); onSuccess?: (() => void) | (() => Promise<void>); windowOpenerFeatures?: string }
      • Optional derivationOrigin?: 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.

        see

        https://github.com/dfinity/internet-identity/blob/main/docs/internet-identity-spec.adoc

      • Optional identityProvider?: string | URL

        Identity provider

        default

        "https://identity.ic0.app"

      • Optional maxTimeToLive?: bigint

        Expiration of the authentication in nanoseconds

        default

        BigInt(8) hours * BigInt(3_600_000_000_000) nanoseconds

      • Optional onError?: ((error?: string) => void) | ((error?: string) => Promise<void>)

        Callback in case authentication fails

      • Optional onSuccess?: (() => void) | (() => Promise<void>)

        Callback once login has completed

      • Optional windowOpenerFeatures?: string

        Configures the opened authentication window

    Returns Promise<void>

  • logout(options?: { returnTo?: string }): Promise<void>
  • Parameters

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

    Returns Promise<void>

  • create(options?: { identity?: SignIdentity; idleOptions?: IdleOptions; keyType?: BaseKeyType; storage?: AuthClientStorage }): Promise<AuthClient>
  • Create an AuthClient to manage authentication and identity

    constructs

    AuthClient

    see

    AuthClientCreateOptions

    see

    {@link SignIdentity}

    see

    {@link AuthClientStorage}

    see

    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 } })

    Parameters

    • options: { identity?: SignIdentity; idleOptions?: IdleOptions; keyType?: BaseKeyType; storage?: AuthClientStorage } = {}
      • Optional identity?: SignIdentity

        An {@link Identity} to use as the base. By default, a new {@link AnonymousIdentity}

      • Optional idleOptions?: IdleOptions

        Options to handle idle timeouts

        default

        after 10 minutes, invalidates the identity

      • 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 storage?: AuthClientStorage

        {@link AuthClientStorage}

        description

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

    Returns Promise<AuthClient>

Generated using TypeDoc