kasperisager/sails-generate-auth — pull request #130 by yedhukrishnan (2014-12-04 12:45:47+00:00)
Title: Add support for API authentication using bearer token

We've added support for API authentication for local strategy using [sails-http-bearer](https://github.com/jaredhanson/passport-http-bearer) module. This is done by adding a new field called `accessToken` in Passport model and generating it automatically while creating a local Passport.

We did that as part of our open source project for mobile device management, [One MDM](https://github.com/multunus/one-mdm/). You can see a working example here: [One MDM Server](http://onemdm.multunus.com/). Login using username `admin` and password `adminadmin`. Get the access token from settings page (top right) and try sending a POST request to [http://onemdm.multunus.com/device/create](http://onemdm.multunus.com/device/create) having params { device: "Some Device Name" } with and without `access_token`. If the request is valid, it will create a new device with the given name in the Devices page. sails-http-bearer allows you to add access_token in 3 ways:

* as a header field (Example: `Authorization: Bearer eWVkaHVUaHUgRGVjIDA0IDIwMTQgMDk6MDg6MjcgR01UKzAwMDAgKFVUQyk=`)
* as a param (Example: `access_token: eWVkaHVUaHUgRGVjIDA0IDIwMTQgMDk6MDg6MjcgR01UKzAwMDAgKFVUQyk=`)
* as a query param

I know that this code can be refactored. But this serves the basic purpose. We put some effort to add API authentication (because most of our APIs are accessed from android devices) and we would like to give it back to the community of sails-generate-auth.

Thanks :)