Skip to content

Commit

Permalink
Merge pull request #7 from chadicus/fea/orScopeLogic
Browse files Browse the repository at this point in the history
Fea/or scope logic
  • Loading branch information
chadicus committed Oct 12, 2015
2 parents 1a0900c + b0aa5f0 commit 277744c
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 67 deletions.
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Chadicus\Slim\OAuth2\Middleware

[![Build Status](http://img.shields.io/travis/chadicus/slim-oauth2-middleware.svg?style=flat)](https://travis-ci.org/chadicus/slim-oauth2-middleware)
[![Build Status](https://travis-ci.org/chadicus/slim-oauth2-middleware.svg?branch=master)](https://travis-ci.org/chadicus/slim-oauth2-middleware)
[![Scrutinizer Code Quality](http://img.shields.io/scrutinizer/g/chadicus/slim-oauth2-middleware.svg?style=flat)](https://scrutinizer-ci.com/g/chadicus/slim-oauth2-middleware/)
[![Code Coverage](http://img.shields.io/coveralls/chadicus/slim-oauth2-middleware.svg?style=flat)](https://coveralls.io/r/chadicus/slim-oauth2-middleware)
[![Coverage Status](https://coveralls.io/repos/chadicus/slim-oauth2-middleware/badge.svg?branch=master&service=github)](https://coveralls.io/github/chadicus/slim-oauth2-middleware?branch=master)

[![Latest Stable Version](http://img.shields.io/packagist/v/chadicus/slim-oauth2-middleware.svg?style=flat)](https://packagist.org/packages/chadicus/slim-oauth2-middleware)
[![Total Downloads](http://img.shields.io/packagist/dt/chadicus/slim-oauth2-middleware.svg?style=flat)](https://packagist.org/packages/chadicus/slim-oauth2-middleware)
Expand Down Expand Up @@ -42,4 +42,58 @@ With a checkout of the code get [Composer](http://getcomposer.org) in your PATH
```sh
./composer install
./vendor/bin/phpunit
```

##Example Usage

Simple example for using the authorization middleware.

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

//set up storage for oauth2 server
$storage = new Storage\Memory(
[
'client_credentials' => [
'testClientId' => [
'client_id' => 'chadicus-app',
'client_secret' => 'password',
],
],
]
);

// create the oauth2 server
$server = new Server(
$storage,
[
'access_lifetime' => 3600,
],
[
new GrantType\ClientCredentials($storage),
]
);

// create the authorization middlware
$authorization = new Middleware\Authorization($server);

$app = new Slim();

//Assumes token endpoints available for creating access tokens

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

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

$app->post('foos', $authorization->withRequiredScope(['superUser']), function () {
//Create a new foo, requires superUser scope
});
```
112 changes: 56 additions & 56 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 277744c

Please sign in to comment.