Giter VIP home page Giter VIP logo

slim-oauth2-routes's Introduction

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();

slim-oauth2-routes's People

Contributors

chadicus avatar

Watchers

 avatar  avatar

Forkers

earllapura

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.