new DefaultAuthenticator() → {amps.DefaultAuthenticator}
This is the constructor for the DefaultAuthenticator class.
Provides the default authentication for simple scenarios when no external actions are required.
Returns:
The created authenticator object.
Example
var myAuthenticator = {
authenticate: function(username, password) {
return new Promise(function(resolve, reject) {
// invoke your authentication mechanism here
verySecureAuthentication(function(err, token) {
if (err) { return reject(err); }
resolve(token);
});
});
},
retry: function(username, password) {
return new Promise(function(resolve, reject) {
// invoke your authentication mechanism here - retry the authentication
retryVerySecureAuthentication(function(err, token) {
if (err) { return reject(err); }
resolve(token);
});
});
},
completed: function(username, password, reason) {
// This method will be invoked upon successful authorization with AMPS
console.log('completed method called: ', reason);
}
};
var client = new amps.Client()
client.connect('ws://localhost:9100/amps/json', myAuthenticator)
.then(function() {
console.log('Connected!');
})
.catch(function(err) {
console.error('connection err: ', err);
});
Methods
authenticate(login, password) → {Promise}
Called by amps.Client, just before the logon command is sent.
Parameters:
Name | Type | Description |
---|---|---|
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:
The Promise object which once fullfilled will contain the value that should be placed
into the Password header for the logon attempt will be passed.
- Type
- Promise
completed(login, password, reason)
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:
Name | Type | Description |
---|---|---|
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. |
retry(login, password) → {Promise}
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:
Name | Type | Description |
---|---|---|
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:
The Promise object which once fullfilled will contain the value that should be placed
into the Password header for the next logon attempt will be passed.
- Type
- Promise