Called by Client, just before the logon command is sent.
The current value of the username as specified in the URI.
The current value of the password, as specified in the URI.
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.
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.
The username that successfully logged on to the server.
The password that successfully logged on to the server.
The reason for this successful completion.
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.
The username returned by the server's ACK message.
The password or token returned in the server's ACK message.
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.
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); }