2017 © Pedro Peláez
 

library slim-oauth2-routes

OAuth2 routes for use within a Slim Framework API

image

chadicus/slim-oauth2-routes

OAuth2 routes for use within a Slim Framework API

  • Tuesday, January 9, 2018
  • by chadicus
  • Repository
  • 0 Watchers
  • 5 Stars
  • 37,923 Installations
  • PHP
  • 1 Dependents
  • 2 Suggesters
  • 8 Forks
  • 0 Open issues
  • 20 Versions
  • 19 % Grown

The README.md

Chadicus\Slim\OAuth2\Routes

Build Status Code Quality Code Coverage, (*1)

Latest Stable Version Latest Unstable Version License, (*2)

Total Downloads Daily Downloads Monthly Downloads, (*3)

Documentation, (*4)

OAuth2 Server route callbacks for use within a Slim 3 Framework API, (*5)

Requirements

Chadicus\Slim\OAuth2\Routes requires PHP 5.6 (or later)., (*6)

Composer

To add the library as a local, per-project dependency use Composer! Simply add a dependency on chadicus/slim-oauth2-routes to your project's composer.json file such as:, (*7)

composer require chadicus/slim-oauth2-routes

Contact

Developers may be contacted at:, (*8)

Project Build

With a checkout of the code get Composer in your PATH and run:, (*9)

./composer install
./vendor/bin/phpunit

A Note on Using Views

The authorize and receive-code route require view objects. The given view object must implement a render method such as the one found in slim/twig-view and slim/php-view. It would be best if there was a common ViewInterface which both implementing but as of now such an interface does not exist., (*10)

Community

Gitter, (*11)

Example Usage

use Chadicus\Slim\OAuth2\Routes;
use OAuth2;
use OAuth2\GrantType;
use OAuth2\Storage;
use Slim;
use Slim\Views;

//Set-up the OAuth2 Server
$storage = new Storage\Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));
$server = new OAuth2\Server($storage);
$server->addGrantType(new GrantType\AuthorizationCode($storage));
$server->addGrantType(new GrantType\ClientCredentials($storage));

//Set-up the Slim Application
$app = new Slim\App(
    [
        'view' => new Views\PhpRenderer('/path/to/chadicus/slim-oauth2-routes/templates'),
    ]
);

$container = $app->getContainer();

$app->map(['GET', 'POST'], Routes\Authorize::ROUTE, new Routes\Authorize($server, $container['view']))->setName('authorize');
$app->post(Routes\Token::ROUTE, new Routes\Token($server))->setName('token');
$app->map(['GET', 'POST'], Routes\ReceiveCode::ROUTE, new Routes\ReceiveCode($container['view']))->setName('receive-code');
$app->post(Routes\Revoke::ROUTE, new Routes\Revoke($server))->setName('revoke');

//Add custom routes
$slim->get('/foo', function($request, $response, $args) {
    $authorization = $request->getHeaderLine('Authorization');

    //validate access token against your storage

    return $response->withStatus(200);
});

//run the app
$app->run();

Authorize and The UserIdProvider

Within the Authorization route, you can define a UserIdProviderInterface to extract the user_id from the incoming request. By default the route will look in the GET query params., (*12)


class ArgumentUserIdProvider implements UserIdProviderInterface { public function getUserId(ServerRequestInterface $request, array $arguments) { return isset($arguments['user_id']) ? $arguments['user_id'] : null; } } //middleware to add user_id to route parameters $loginMiddelware = function ($request, $response, $next) { // Validate the user credentials $userId = MyUserService::getUserIdIfValidCredentials($request); if ($userId === false) { return $response->withStatus(303); } //Put user_id into the route parameters $route = $request->getAttribute('route'); $route->setArgument('user_id', $userId); //Credentials are valid, continue so the authorization code can be sent to the clients callback_uri return $next($request, $response); }; $authorizeRoute = new Routes\Authorize($server, $view, 'authorize.phtml', new ArgumentUserIdProvider()); $app->map( ['GET', 'POST'], Routes\Authorize::ROUTE, $authorizeRoute )->add($loginMiddleware)->setName('authorize');

The Versions

09/01 2018

dev-chadicus-patch-1

dev-chadicus-patch-1

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

08/01 2018

dev-master

9999999-dev

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

08/01 2018
08/01 2018

dev-dev/composer

dev-dev/composer

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

10/01 2017
04/01 2017
02/12 2016
15/11 2016
23/05 2016

v3.0.2

3.0.2.0

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

23/05 2016

v3.0.1

3.0.1.0

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

22/05 2016

v3.0.0

3.0.0.0

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

27/04 2016

v1.x-dev

1.9999999.9999999.9999999-dev

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

27/04 2016

v1.1.0

1.1.0.0

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

05/02 2016

v1.0.0

1.0.0.0

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

23/09 2015

v0.2.1

0.2.1.0

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

22/09 2015

v0.2.0

0.2.0.0

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

29/07 2015

v0.1.3

0.1.3.0

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

24/07 2015

v0.1.2

0.1.2.0

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

23/07 2015

v0.1.1

0.1.1.0

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim

23/07 2015

v0.1.0

0.1.0.0

OAuth2 routes for use within a Slim Framework API

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth2 routing slim