Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Authenticator

This is the authenticator interface that is used by the client during the logging on. It provides the authentication for custom authentication scenarios when external actions are required before logging on.

Example:

class MyAuthenticator {
    async authenticate(username, password) {
         // invoke your authentication mechanism here
         const token = await verySecureAuthentication();
         console.log('Token Received:', token);

         return token;
    }

    async retry(username, password) {
         // invoke your authentication mechanism here - retry the authentication
         return this.authenticate(username, password);
    }

    completed(username, password, reason) {
        // This method will be invoked upon successful authorization with AMPS
        console.log('completed method called: ', reason);
    }
}


try {
    const client = new Client();
    await client.connect('ws://localhost:9100/amps/json', myAuthenticator);
    console.log('Connected!');
}
catch (err) {
    console.error('connection err: ', err);
}

Hierarchy

  • Authenticator

Index

Methods

authenticate

  • authenticate(login: string, password: string): Promise<string>
  • Called by Client, just before the logon command is sent.

    Parameters

    • login: string

      The current value of the username as specified in the URI.

    • password: string

      The current value of the password, as specified in the URI.

    Returns Promise<string>

    The Promise object which once fulfilled will contain the value that should be placed into the Password header for the logon attempt will be passed.

completed

  • completed(login: string, password: string, reason: string): void
  • Called when a logon completes successfully. Once a logon has completed, this method is called with the username and password that caused a successful logon.

    Parameters

    • login: string

      The username that successfully logged on to the server.

    • password: string

      The password that successfully logged on to the server.

    • reason: string

      The reason for this successful completion.

    Returns void

retry

  • retry(login: string, password: string): Promise<string>
  • Called when a logon "ack" is received with a status of "retry". AMPS will continue trying to logon as long as the server returns "retry", and this method continues to succeed.

    Parameters

    • login: string

      The username returned by the server's ACK message.

    • password: string

      The password or token returned in the server's ACK message.

    Returns Promise<string>

    The Promise object which once fulfilled will contain the value that should be placed into the Password header for the next logon attempt will be passed.