ushahidi/Lamu — pull request #43 by rjmackay (2013-04-28 23:13:50+00:00)
Title: Adding basic OAuth2 support

Adding basic oauth2 support.
I've use this library to do most of the handling https://github.com/bshaffer/oauth2-server-php
I've added endpoints and tests for
* Auth code grant
* Implicit grant
* Resource owner credentials
Only supporting bearer tokens

Added a basic access check to API to ensure that we get passed an access token, its valid and it has the required scope.

I've added a driver to store oauth data in the DB. And a migration script to install new tables. This is under application rather than the oauth module otherwise it didn't work.

What I haven't done:
* added a user ACL yet - so all users can be granted any scope, and can access any resources
* added user login - authorize requests just get a basic yes/no form without any login
* Testing refresh tokens. These are supported in the library but I haven't checked if they work.
* Tested client credentials grant - again should work but haven't tried.
* 401 Oauth errors aren't quite right since more error info should be in the WWW-Authenticate header.
* Haven't checked everything against the spec in detail yet.
* Also need to standardize class names in my module and rename to something like 'koauth2'

To run the tests you'll need to grab the dependencies I've added in composer.json. This adds mink and goutte to run the oauth2 tests. This was needed to simulate a user actually hitting the 'Authorize' button.

Other changes
* Changed some steps in RestContext to avoid clashing with MinkContext. This is why I've touched other test features
* Overriding HTTP_Exception_401 to return body content. Otherwise we get no useful feedback from token auth errors.