eclipse/ponte — pull request #12 by healarconr (2014-10-23 04:09:40+00:00)
Title: Authentication and authorization callbacks

Hi,

I added authentication and authorization callbacks for the CoAP, HTTP and MQTT servers, along with the corresponding unit tests. The callbacks for the MQTT server follow the exact same structure as the ones used in Mosca: [https://github.com/mcollina/mosca/wiki/Authentication-&-Authorization](https://github.com/mcollina/mosca/wiki/Authentication-&-Authorization). The callbacks for the CoAP and HTTP servers are a little bit different:

* The callback function passed to the authenticate callback should receive an object that represents the authenticated subject. This object should contain the data required to perform the authorization. Here are some examples:

```
function authenticate(req, callback) {
// Error: callback(error);
// Authenticated: callback(null, true, { username: 'someone' });
// Not authenticated: callback(null, false);
}
```

* The authorize methods are named:```authorizeGet``` and ```authorizePut```. They receive the subject returned by the authenticate function, the topic, and the ```authorizePut``` also receives the payload.

The callback configuration is done along with the configuration of all the other parameters. These are the new elements that should be added (See README.md for more details):

```
{
coap: {
authenticate: function(req, callback) {
// ...
},
authorizeGet: function(subject, topic, callback) {
// ...
},
authorizePut: function(subject, topic, payload, callback) {
// ...
}
},
http: {
authenticate: function(req, callback) {
// ...
},
authorizeGet: function(subject, topic, callback) {
// ...
},
authorizePut: function(subject, topic, payload, callback) {
// ...
}
},
mqtt: {
authenticate: function(client, username, password, callback) {
// ...
},
authorizePublish: function(client, topic, payload, callback) {
// ...
},
authorizeSubscribe: function(client, topic, callback) {
// ...
}
}
```

All the servers have default authentication and authorization callbacks that authenticate and authorize everybody.