Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents an instance of a signed in user for a particular app.

A signed in user has access to two major pieces of information about the user, the user's private key for that app and the location of the user's gaia storage bucket for the app.

A user can be signed in either directly through the interactive sign in process or by directly providing the app private key.

Hierarchy

  • UserSession

Index

Constructors

constructor

  • new UserSession(options?: { appConfig?: AppConfig; sessionOptions?: SessionOptions; sessionStore?: SessionDataStore }): UserSession
  • Creates a UserSession object

    Parameters

    • Optional options: { appConfig?: AppConfig; sessionOptions?: SessionOptions; sessionStore?: SessionDataStore }
      • Optional appConfig?: AppConfig
      • Optional sessionOptions?: SessionOptions
      • Optional sessionStore?: SessionDataStore

    Returns UserSession

Properties

appConfig

appConfig: AppConfig

store

store: SessionDataStore

Methods

decryptContent

  • decryptContent(content: string, options?: { privateKey?: string }): Promise<string | Buffer>
  • Decrypts data encrypted with encryptContent with the transit private key.

    Parameters

    • content: string

      encrypted content.

    • Optional options: { privateKey?: string }
      • Optional privateKey?: string

        The hex string of the ECDSA private key to use for decryption. If not provided, will use user's appPrivateKey.

    Returns Promise<string | Buffer>

    decrypted content.

encryptContent

generateAndStoreTransitKey

  • generateAndStoreTransitKey(): string
  • Generates a ECDSA keypair to use as the ephemeral app transit private key and store in the session.

    Returns string

    the hex encoded private key

getAuthResponseToken

  • getAuthResponseToken(): string

handlePendingSignIn

  • handlePendingSignIn(authResponseToken?: string): Promise<UserData>
  • Try to process any pending sign in request by returning a Promise that resolves to the user data object if the sign in succeeds.

    Parameters

    • authResponseToken: string = ...

      the signed authentication response token

    Returns Promise<UserData>

    that resolves to the user data object if successful and rejects if handling the sign in request fails or there was no pending sign in request.

isSignInPending

  • isSignInPending(): boolean
  • Check if there is a authentication request that hasn't been handled.

    Also checks for a protocol echo reply (which if detected then the page will be automatically redirected after this call).

    Returns boolean

    true if there is a pending sign in, otherwise false

isUserSignedIn

  • isUserSignedIn(): boolean

loadUserData

makeAuthRequest

  • makeAuthRequest(transitKey?: string, redirectURI?: string, manifestURI?: string, scopes?: string[], appDomain?: string, expiresAt?: number, extraParams?: any): string
  • Generates an authentication request that can be sent to the Blockstack browser for the user to approve sign in. This authentication request can then be used for sign in by passing it to the [[redirectToSignInWithAuthRequest]] method.

    Note: This method should only be used if you want to use a customized authentication flow. Typically, you'd use [[redirectToSignIn]] which is the default sign in method.

    Parameters

    • Optional transitKey: string

      A HEX encoded transit private key.

    • Optional redirectURI: string

      Location to redirect the user to after sign in approval.

    • Optional manifestURI: string

      Location of this app's manifest file.

    • Optional scopes: string[]

      The permissions this app is requesting. The default is store_write.

    • Optional appDomain: string

      The origin of the app.

    • expiresAt: number = ...

      The time at which this request is no longer valid.

    • extraParams: any = {}

      Any extra parameters to pass to the authenticator. Use this to pass options that aren't part of the Blockstack authentication specification, but might be supported by special authenticators.

    Returns string

    the authentication request

signUserOut

  • signUserOut(redirectURL?: string): void
  • Sign the user out and optionally redirect to given location.

    Parameters

    • Optional redirectURL: string

      Location to redirect user to after sign out. Only used in environments with window available

    Returns void

Generated using TypeDoc