Skip to content

Commit

Permalink
Merge branch 'release/3.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
hswong3i committed Jul 29, 2015
2 parents 43aeb13 + 55efe8d commit 3ee31ab
Show file tree
Hide file tree
Showing 223 changed files with 882 additions and 2,101 deletions.
16 changes: 13 additions & 3 deletions .php-cs-fixer.php
@@ -1,6 +1,11 @@
<?php

return Symfony\CS\Config\Config::create()->finder(Symfony\CS\Finder\DefaultFinder::create()
$fixers = array(
'-psr0',
'-no_empty_lines_after_phpdocs',
);

$finder = Symfony\CS\Finder\DefaultFinder::create()
->exclude('app/cache')
->exclude('app/log')
->exclude('build')
Expand All @@ -10,5 +15,10 @@
->notName('LICENSE')
->notName('README.md')
->notName('composer.*')
->notName('phpunit.xml*')
);
->notName('phpunit.xml*');

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->setUsingCache(false)
->fixers($fixers)
->finder($finder);
19 changes: 13 additions & 6 deletions .travis.yml
@@ -1,21 +1,28 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

before_install:
- composer self-update

install:
- composer install --prefer-source

before_script:
- echo 'memory_limit = -1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- composer install --dev --prefer-source
- mkdir -p build/logs
- rm -rf app/cache/*/*

script:
- vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover ./build/logs/clover.xml
- composer phpunit

after_script:
- php vendor/bin/coveralls -v
- composer coveralls

matrix:
allow_failures:
- php: 7.0
- php: hhvm
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Wong Hoi Sing Edison
Copyright (c) 2015 Wong Hoi Sing Edison

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
95 changes: 45 additions & 50 deletions README.md
Expand Up @@ -4,7 +4,7 @@ AuthBucket\\OAuth2
[![Build
Status](https://travis-ci.org/authbucket/oauth2-php.svg?branch=master)](https://travis-ci.org/authbucket/oauth2-php)
[![Coverage
Status](https://img.shields.io/coveralls/authbucket/oauth2-php.svg)](https://coveralls.io/r/authbucket/oauth2-php?branch=master)
Status](https://coveralls.io/repos/authbucket/oauth2-php/badge.svg?branch=master&service=github)](https://coveralls.io/github/authbucket/oauth2-php?branch=master)
[![Dependency
Status](https://www.versioneye.com/php/authbucket:oauth2-php/dev-master/badge.svg)](https://www.versioneye.com/php/authbucket:oauth2-php/dev-master)
[![Latest Stable
Expand All @@ -21,7 +21,7 @@ would be develop corresponding wrapper [Symfony2
Bundle](http://symfony.com) and [Drupal module](https://www.drupal.org).

This library bundle with a [Silex](http://silex.sensiolabs.org/) based
[AuthBucketOAuth2ServiceProvider](https://github.com/authbucket/oauth2-php/blob/master/src/AuthBucket/OAuth2/Provider/AuthBucketOAuth2ServiceProvider.php)
[AuthBucketOAuth2ServiceProvider](https://github.com/authbucket/oauth2-php/blob/master/src/Provider/AuthBucketOAuth2ServiceProvider.php)
for unit test and demo purpose. Installation and usage can refer as
below.

Expand All @@ -36,14 +36,14 @@ Here is a minimal example of a `composer.json`:

{
"require": {
"authbucket/oauth2-php": "~2.4"
"authbucket/oauth2-php": "~3.0"
}
}

### Parameters

The bundled
[AuthBucketOAuth2ServiceProvider](https://github.com/authbucket/oauth2-php/blob/master/src/AuthBucket/OAuth2/Provider/AuthBucketOAuth2ServiceProvider.php)
[AuthBucketOAuth2ServiceProvider](https://github.com/authbucket/oauth2-php/blob/master/src/Provider/AuthBucketOAuth2ServiceProvider.php)
come with following parameters:

- `authbucket_oauth2.model`: (Optional) Override this with your own
Expand All @@ -61,35 +61,25 @@ come with following parameters:
### Services

The bundled
[AuthBucketOAuth2ServiceProvider](https://github.com/authbucket/oauth2-php/blob/master/src/AuthBucket/OAuth2/Provider/AuthBucketOAuth2ServiceProvider.php)
[AuthBucketOAuth2ServiceProvider](https://github.com/authbucket/oauth2-php/blob/master/src/Provider/AuthBucketOAuth2ServiceProvider.php)
come with following services controller which simplify the OAuth2.0
controller implementation overhead:

- `authbucket_oauth2.oauth2_controller`: OAuth2 endpoint controller.

Moreover, we also provide following model
[CRUD](http://en.wikipedia.org/wiki/Create,_read,_update_and_delete)
controller for alter raw data set:

- `authbucket_oauth2.authorize_controller`: Authorize endpoint
controller.
- `authbucket_oauth2.client_controller`: Client endpoint controller.
- `authbucket_oauth2.scope_controller`: Scope endpoint controller.

### Registering

If you are using [Silex](http://silex.sensiolabs.org/), register
[AuthBucketOAuth2ServiceProvider](https://github.com/authbucket/oauth2-php/blob/master/src/AuthBucket/OAuth2/Provider/AuthBucketOAuth2ServiceProvider.php)
[AuthBucketOAuth2ServiceProvider](https://github.com/authbucket/oauth2-php/blob/master/src/Provider/AuthBucketOAuth2ServiceProvider.php)
as below:

$app->register(new AuthBucket\OAuth2\Provider\AuthBucketOAuth2ServiceProvider());

Moreover, enable following service providers if that's not already the
case:

$app->register(new Silex\Provider\MonologServiceProvider());
$app->register(new Silex\Provider\SecurityServiceProvider());
$app->register(new Silex\Provider\SerializerServiceProvider());
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
$app->register(new Silex\Provider\ValidatorServiceProvider());

Usage
Expand All @@ -100,12 +90,16 @@ backend controller point of view, so you will need to setup both for
functioning.

To enable the built-in controller with corresponding routing, you need
to mount it with a shared provider instance, all above controllers will
be enabled accordingly with routing prefix `/api/v1.0`:
to mount it manually:

$app->get('/api/oauth2/authorize', 'authbucket_oauth2.oauth2_controller:authorizeAction')
->bind('api_oauth2_authorize');

$app->post('/api/oauth2/token', 'authbucket_oauth2.oauth2_controller:tokenAction')
->bind('api_oauth2_token');

$provider = new AuthBucket\OAuth2\Provider\AuthBucketOAuth2ServiceProvider();
$app->register($provider);
$app->mount('/', $provider);
$app->match('/api/oauth2/debug', 'authbucket_oauth2.oauth2_controller:debugAction')
->bind('api_oauth2_debug');

Below is a list of recipes that cover some common use cases.

Expand All @@ -117,7 +111,7 @@ e.g. by
[SecurityServiceProvider](http://silex.sensiolabs.org/doc/providers/security.html):

$app['security.encoder.digest'] = $app->share(function ($app) {
return new PlaintextPasswordEncoder();
return new Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder();
});

$app['security.user_provider.default'] = $app['security.user_provider.inmemory._proto'](array(
Expand All @@ -127,8 +121,8 @@ e.g. by
));

$app['security.firewalls'] = array(
'oauth2_authorize' => array(
'pattern' => '^/api/v1.0/oauth2/authorize$',
'api_oauth2_authorize' => array(
'pattern' => '^/api/oauth2/authorize$',
'http' => true,
'users' => $app['security.user_provider.default'],
),
Expand All @@ -140,8 +134,8 @@ Similar as authorization endpoint, we need to protect this endpoint with
our custom firewall `oauth2_token`:

$app['security.firewalls'] = array(
'oauth2_token' => array(
'pattern' => '^/api/v1.0/oauth2/token$',
'api_oauth2_token' => array(
'pattern' => '^/api/oauth2/token$',
'oauth2_token' => true,
),
);
Expand All @@ -152,10 +146,10 @@ We should protect this endpoint with our custom firewall
`oauth2_resource`:

$app['security.firewalls'] = array(
'oauth2_debug' => array(
'pattern' => '^/api/v1.0/oauth2/debug$',
'oauth2_resource' => true,
),
'api_oauth2_debug' => array(
'pattern' => '^/api/oauth2/debug$',
'oauth2_resource' => true,
),
);

### Resource Endpoint
Expand All @@ -171,8 +165,8 @@ resource server bundled with authorization server, query local model
manager, without scope protection):

$app['security.firewalls'] = array(
'resource' => array(
'pattern' => '^/api/v1.0/resource',
'api_resource' => array(
'pattern' => '^/api/resource',
'oauth2_resource' => true,
),
);
Expand All @@ -181,8 +175,8 @@ Longhand version (assume resource server bundled with authorization
server, query local model manager, protect with scope `demoscope1`):

$app['security.firewalls'] = array(
'resource' => array(
'pattern' => '^/api/v1.0/resource',
'api_resource' => array(
'pattern' => '^/api/resource',
'oauth2_resource' => array(
'resource_type' => 'model',
'scope' => array('demoscope1'),
Expand All @@ -195,14 +189,15 @@ local resource endpoint by query remote authorization server debug
endpoint:

$app['security.firewalls'] = array(
'resource' => array(
'pattern' => '^/api/v1.0/resource',
'api_resource' => array(
'pattern' => '^/api/resource',
'oauth2_resource' => array(
'resource_type' => 'debug_endpoint',
'scope' => array('demoscope1'),
'options' => array(
'debug_endpoint' => 'http://example.com/api/v1.0/oauth2/debug',
'cache' => true,
'resource_type' => 'debug_endpoint',
'scope' => array('demoscope1'),
'options' => array(
'debug_endpoint' => 'http://example.com/api/oauth2/debug',
'cache' => true,
),
),
),
);
Expand All @@ -211,20 +206,20 @@ Demo
----

The demo is based on [Silex](http://silex.sensiolabs.org/) and
[AuthBucketOAuth2ServiceProvider](https://github.com/authbucket/oauth2-php/blob/master/src/AuthBucket/OAuth2/Provider/AuthBucketOAuth2ServiceProvider.php).
[AuthBucketOAuth2ServiceProvider](https://github.com/authbucket/oauth2-php/blob/master/src/Provider/AuthBucketOAuth2ServiceProvider.php).
Read though [Demo](http://oauth2-php.authbucket.com/demo) for more
information.

You may also run the demo locally. Open a console and execute the
following command to install the latest version in the `oauth2-php`
directory:

$ composer create-project authbucket/oauth2-php oauth2-php "~2.4"
$ composer create-project authbucket/oauth2-php authbucket/oauth2-php "~3.0"

Then use the PHP built-in web server to run the demo application:

$ cd oauth2-php
$ php app/console server:run
$ cd authbucket/oauth2-php
$ ./app/console server:run

If you get the error
`There are no commands defined in the "server" namespace.`, then you are
Expand All @@ -249,7 +244,7 @@ Pages](http://authbucket.github.io/oauth2-php).

To built the documents locally, execute the following command:

$ vendor/bin/sami.php update .sami.php
$ composer sami

Open `build/sami/index.html` with your browser for the documents.

Expand All @@ -264,7 +259,7 @@ can be found from

To run the test suite locally, execute the following command:

$ vendor/bin/phpunit
$ composer phpunit

Open `build/logs/html` with your browser for the coverage report.

Expand All @@ -284,5 +279,5 @@ License

- Code released under
[MIT](https://github.com/authbucket/oauth2-php/blob/master/LICENSE)
- Docs released under [CC BY-NC-SA
3.0](http://creativecommons.org/licenses/by-nc-sa/3.0/)
- Docs released under [CC BY
4.0](http://creativecommons.org/licenses/by/4.0/)
7 changes: 7 additions & 0 deletions app/.htaccess
@@ -0,0 +1,7 @@
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
23 changes: 12 additions & 11 deletions app/AppKernel.php
Expand Up @@ -11,25 +11,26 @@

use Symfony\Component\HttpFoundation\Request;

$app->register(new AuthBucket\OAuth2\Tests\TestBundle\TestBundleServiceProvider());
# Register MUST have Silex providers for AuthBucketOAuth2ServiceProvider.
$app->register(new Silex\Provider\MonologServiceProvider());
$app->register(new Silex\Provider\SecurityServiceProvider());
$app->register(new Silex\Provider\ValidatorServiceProvider());

# Register AuthBucketOAuth2ServiceProvider.
$app->register(new AuthBucket\OAuth2\Provider\AuthBucketOAuth2ServiceProvider());

# Register additional Silex providers for TestBundleServiceProvider.
$app->register(new Silex\Provider\DoctrineServiceProvider());
$app->register(new Silex\Provider\FormServiceProvider());
$app->register(new Silex\Provider\SecurityServiceProvider());
$app->register(new Silex\Provider\SerializerServiceProvider());
$app->register(new Silex\Provider\RememberMeServiceProvider());
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider());
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\ValidatorServiceProvider());

# Before registering this service provider, you must register the SecurityServiceProvider.
$app->register(new Silex\Provider\RememberMeServiceProvider());

# Register and mount with same provider.
$provider = new AuthBucket\OAuth2\Provider\AuthBucketOAuth2ServiceProvider();
$app->register($provider);
$app->mount('/', $provider);
# Register TestBundleServiceProvider.
$app->register(new AuthBucket\OAuth2\Tests\TestBundle\TestBundleServiceProvider());

require __DIR__.'/config/config_'.$app['env'].'.php';

Expand Down
13 changes: 13 additions & 0 deletions app/autoload.php
@@ -0,0 +1,13 @@
<?php

use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;

/*
* @var ClassLoader
*/
$loader = require __DIR__.'/../vendor/autoload.php';

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

return $loader;

0 comments on commit 3ee31ab

Please sign in to comment.