Skip to content

Commit

Permalink
Merge pull request #17 from chadicus/slim3
Browse files Browse the repository at this point in the history
Slim3
  • Loading branch information
chadicus committed May 22, 2016
2 parents 4d9d390 + 0ed1ada commit 3767399
Show file tree
Hide file tree
Showing 11 changed files with 797 additions and 452 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md → .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Code changes should be sent through [GitHub Pull Requests](https://github.com/ch

While the build does not enforce 100% [PHPUnit](http://www.phpunit.de) code coverage, it will not allow coverage to drop below its current percentage.

The build will also not allow any errors for the [coding standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md).
The build will also not allow any errors for the [coding standard](http://chadicus.github.io/coding-standard/)

```sh
./vendor/bin/phpcs --standard=PSR2 src tests
./vendor/bin/phpcs --standard=./vendor/chadicus/coding-standard/Chadicus src tests
```
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Expected Behavior

## Actual Behavior

## Steps to reproduce the behavior

8 changes: 8 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Fixes # .

#### What does this PR do?

#### Checklist
- [ ] Pull request contains a clear definition of changes
- [ ] Tests (either unit, integration, or acceptance) written and passing
- [ ] Relevant documentation produced and/or updated
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tools:
php_pdepend: true
php_sim: true
build_failure_conditions:
- 'elements.rating(<= B).new.exists'
- 'elements.rating(< B).new.exists'
- 'issues.label("coding-style").new.exists'
- 'issues.severity(>= MAJOR).new.exists'
- 'project.metric("scrutinizer.quality", < 6)'
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
language: php
php:
- 5.6
- 5.5
- 7
- hhvm
install: composer install
script: ./vendor/bin/phpunit --coverage-clover clover.xml
after_success: sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" -a "$TRAVIS_PHP_VERSION" != "7" ]; then ./vendor/bin/coveralls -v; fi'
after_success: sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then ./vendor/bin/coveralls -v; fi'
matrix:
fast_finish: true
allow_failures:
- php: 7
- php: hhvm
37 changes: 22 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

[![Documentation](https://img.shields.io/badge/reference-phpdoc-blue.svg?style=flat)](http://pholiophp.org/chadicus/slim-oauth2-middleware)

Middleware for Using OAuth2 within a Slim Framework API
Middleware for using [OAuth2 Server](http://bshaffer.github.io/oauth2-server-php-docs/) within a [Slim 3 Framework](http://www.slimframework.com/) API

## Requirements

Chadicus\Slim\OAuth2\Middleware requires PHP 5.5 (or later).
Chadicus\Slim\OAuth2\Middleware requires PHP 5.6 (or later).

##Composer
To add the library as a local, per-project dependency use [Composer](http://getcomposer.org)! Simply add a dependency on
Expand All @@ -28,7 +28,7 @@ To add the library as a local, per-project dependency use [Composer](http://getc
```json
{
"require": {
"chadicus/slim-oauth2-middleware": "~1.0"
"chadicus/slim-oauth2-middleware": "~3.0"
}
}
```
Expand All @@ -53,10 +53,10 @@ Simple example for using the authorization middleware.

```php
use Chadicus\Slim\OAuth2\Middleware;
use OAuth2\Server;
use OAuth2;
use OAuth2\Storage;
use OAuth2\GrantType;
use Slim\Slim;
use Slim;

//set up storage for oauth2 server
$storage = new Storage\Memory(
Expand All @@ -71,7 +71,7 @@ $storage = new Storage\Memory(
);

// create the oauth2 server
$server = new Server(
$server = new OAuth2\Server(
$storage,
[
'access_lifetime' => 3600,
Expand All @@ -81,22 +81,29 @@ $server = new Server(
]
);

// create the authorization middlware
$authorization = new Middleware\Authorization($server);
//create the basic app
$app = new Slim\App();

$app = new Slim();
// create the authorization middlware
$authMiddleware = new Middleware\Authorization($server, $app->getContainer());

//Assumes token endpoints available for creating access tokens

$app->get('foos', $authorization, function () {
$app->get('foos', function ($request, $response, $args) {
//return all foos, no scope required
});
})->add($authMiddleware);

$app->get('foos/id', $authorization->withRequiredScope(['superUser', ['basicUser', 'canViewFoos']]), function ($id) {
$getRouteCallback = function ($request, $response, $id) {
//return details for a foo, requires superUser scope OR basicUser with canViewFoos scope
});
};

$app->get('foos/id', $getRouteCallback)->add($authMiddleware->withRequiredScope(['superUser', ['basicUser', 'canViewFoos']]));

$app->post('foos', $authorization->withRequiredScope(['superUser']), function () {
$postRouteCallback = function ($request, $response, $args) {
//Create a new foo, requires superUser scope
});
};

$app->post('foos', $postRouteCallback)->add($authMiddleware->withRequiredScope(['superUser']));

$app->run();
```
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
],
"license": "MIT",
"require": {
"php": "~5.5 || ~7.0",
"bshaffer/oauth2-server-php": "~1.7",
"slim/slim": "~2.0",
"chadicus/slim-oauth2-http": "~1.0"
"php": "~5.6 || ~7.0",
"bshaffer/oauth2-server-php": "~1.8",
"slim/slim": "~3.0",
"chadicus/slim-oauth2-http": "~3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpunit/phpunit": "~5.0",
"chadicus/coding-standard": "~1.0",
"satooshi/php-coveralls": "~0.6.1"
"satooshi/php-coveralls": "~1.0"
},
"autoload": {
"psr-4": {"Chadicus\\Slim\\OAuth2\\Middleware\\" : "src"}
Expand Down
Loading

0 comments on commit 3767399

Please sign in to comment.