Class InteractiveAuth<T>

Abstracts the logic used to drive the interactive auth process.

Components implementing an interactive auth flow should instantiate one of these, passing in the necessary callbacks to the constructor. They should then call attemptAuth, which will return a promise which will resolve or reject when the interactive-auth process completes.

Meanwhile, calls will be made to the startAuthStage and doRequest callbacks, and information gathered from the user can be submitted with submitAuthDict.

Param: opts

options object

Type Parameters

  • T

    the return type of the request when it is successful

Constructors

Properties

attemptAuthDeferred: null | IDeferred<T> = null
busyChangedCallback?: ((busy) => void)

Type declaration

    • (busy): void
    • Called whenever the interactive auth logic becomes busy submitting information provided by the user or finishes. After this has been called with true the UI should indicate that a request is in progress until it is called again with false.

      Parameters

      • busy: boolean

      Returns void

chosenFlow: null | UIAFlow = null
clientSecret: string
currentStage: null | string = null
emailAttempt: number = 1
emailSid?: string
inputs: IInputs
matrixClient: MatrixClient
requestCallback: ((auth, background) => Promise<T>)

Type declaration

    • (auth, background): Promise<T>
    • Called with the new auth dict to submit the request. Also passes a second deprecated arg which is a flag set to true if this request is a background request. The busyChanged callback should be used instead of the background flag. Should return a promise which resolves to the successful response or rejects with a MatrixError.

      Parameters

      • auth: null | AuthDict
      • background: boolean

      Returns Promise<T>

requestEmailTokenCallback: ((email, secret, attempt, session) => Promise<{
    sid: string;
}>)

Type declaration

    • (email, secret, attempt, session): Promise<{
          sid: string;
      }>
    • A function that takes the email address (string), clientSecret (string), attempt number (int) and sessionId (string) and calls the relevant requestToken function and returns the promise returned by that function. If the resulting promise rejects, the rejection will propagate through to the attemptAuth promise.

      Parameters

      • email: string
      • secret: string
      • attempt: number
      • session: string

      Returns Promise<{
          sid: string;
      }>

requestingEmailToken: boolean = false
stateUpdatedCallback: ((nextStage, status) => void)

Type declaration

    • (nextStage, status): void
    • Called when the status of the UI auth changes, ie. when the state of an auth stage changes of when the auth flow moves to a new stage. The arguments are: the login type (eg m.login.password); and an object which is either an error or an informational object specific to the login type. If the 'errcode' key is defined, the object is an error, and has keys: errcode: string, the textual error code, eg. M_UNKNOWN error: string, human readable string describing the error

      The login type specific objects are as follows: m.login.email.identity: * emailSid: string, the sid of the active email auth session

      Parameters

      Returns void

submitPromise: null | Promise<void> = null
supportedStages?: Set<string>

Methods

  • begin the authentication process.

    Returns Promise<T>

    which resolves to the response on success, or rejects with the error on failure. Rejects with NoAuthFlowFoundError if no suitable authentication flow can be found

  • Internal

    Pick one of the flows from the returned list If a flow using all of the inputs is found, it will be returned, otherwise, null will be returned.

    Only flows using all given inputs are chosen because it is likely to be surprising if the user provides a credential and it is not used. For example, for registration, this could result in the email not being used which would leave the account with no means to reset a password.

    Returns UIAFlow

    flow

    Throws

    NoAuthFlowFoundError If no suitable authentication flow can be found

  • Internal

    Fire off a request, and either resolve the promise, or call startAuthStage.

    Parameters

    • auth: null | AuthDict

      new auth dict, including session id

    • background: boolean = false

      If true, this request is a background poll, so it failing will not result in the attemptAuth promise being rejected. This can be set to true for requests that just poll to see if auth has been completed elsewhere.

    Returns Promise<void>

  • Internal

    Get the first uncompleted stage in the given flow

    Parameters

    Returns undefined | string

    login type

  • get the client secret used for validation sessions with the identity server.

    Returns string

    client secret

  • Gets the sid for the email validation session Specific to m.login.email.identity

    Returns undefined | string

    The sid of the email auth session

  • get the server params for a given stage

    Parameters

    • loginType: string

      login type for the stage

    Returns undefined | Record<string, any>

    any parameters from the server for this stage

  • Poll to check if the auth session or current stage has been completed out-of-band. If so, the attemptAuth promise will be resolved.

    Returns Promise<void>

  • Sets the sid for the email validation session This must be set in order to successfully poll for completion of the email validation. Specific to m.login.email.identity

    Parameters

    • sid: string

      The sid for the email validation session

    Returns void

  • submit a new auth dict and fire off the request. This will either make attemptAuth resolve/reject, or cause the startAuthStage callback to be called for a new stage.

    Parameters

    • authData: AuthDict

      new auth dict to send to the server. Should include a type property denoting the login type, as well as any other params for that stage.

    • background: boolean = false

      If true, this request failing will not result in the attemptAuth promise being rejected. This can be set to true for requests that just poll to see if auth has been completed elsewhere.

    Returns Promise<void>

Generated using TypeDoc