Skip to content

DavidWiesner/slim-oauth2-routes

 
 

Repository files navigation

Chadicus\Slim\OAuth2\Routes

Build Status Code Quality Code Coverage Dependency Status

Latest Stable Version Latest Unstable Version License

Total Downloads Daily Downloads Monthly Downloads

Documentation

OAuth2 routes for use within a Slim Framework API

Requirements

Chadicus\Slim\OAuth2\Routes requires PHP 5.4 (or later).

##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:

{
    "require": {
        "chadicus/slim-oauth2-routes": "dev-master"
    }
}

##Contact Developers may be contacted at:

##Project Build With a checkout of the code get Composer in your PATH and run:

./composer install
./vendor/bin/phpunit

##Example Usage

use Chadicus\Slim\OAuth2\Routes;

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

//Set-up the Slim Application
$slim = new \Slim\Slim();

//By default templates are found in this repositories templates folder.
$slim->config('templates.path', '/path/to/chadicus/slim-oauth2-routes/templates');

Routes\Token::register($slim, $server);
//You can add your custom authorize template here
Routes\Authorize::register($slim, $server, 'authorize.phtml');
//You can add your custom receive-code template here
Routes\ReceiveCode::register($slim, 'receive-code.phtml');

//Add custom routes
$slim->get('/foo', function() use ($slim) {
    if(!isset($slim->request->headers['Authorization'])) {
        $slim->response->headers->set('Content-Type', 'application/json');
        $slim->response->setStatus(400);
        $slim->response->setBody(json_encode(['error' => 'Access credentials not supplied']));
        return;
    }

    $authorization = $slim->request->headers['Authorization'];

    //validate access token against your storage

    $slim->response->setBody('valid credentials');
});

$slim->run();

About

OAuth2 routes for use within a Slim Framework API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 98.2%
  • HTML 1.8%