Options
All
  • Public
  • Public/Protected
  • All
Menu

Tool to manage authentication and identity

see

AuthClient

Hierarchy

  • AuthClient

Index

Constructors

  • Parameters

    • _identity: Identity
    • _key: null | 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): void
  • Parameters

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

    Returns void

  • _removeEventListener(): void
  • getIdentity(): Identity
  • isAuthenticated(): Promise<boolean>
  • login(options?: { 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://.localhost: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: { identityProvider?: string | URL; maxTimeToLive?: bigint; onError?: ((error?: string) => void) | ((error?: string) => Promise<void>); onSuccess?: (() => void) | (() => Promise<void>); windowOpenerFeatures?: string }
      • 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

        Auth Window feature config string

        example

        "toolbar=0,location=0,menubar=0,width=500,height=500,left=100,top=100"

    Returns Promise<void>

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

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

    Returns Promise<void>

  • Create an AuthClient to manage authentication and identity

    constructs

    AuthClient

    see

    AuthClientCreateOptions

    see

    {@link SignIdentity}

    see

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

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

    Returns Promise<AuthClient>

Generated using TypeDoc