See this Laravel demo application for implementing this library in Laravel 4.

Step-By-Step Walkthrough

  1. Create your Laravel project (e.g. composer create-project laravel/laravel --prefer-dist)
  2. Install the OAuth2 server and HTTPFoundation bridge dependencies using Composer: composer require bshaffer/oauth2-server-php and composer require bshaffer/oauth2-server-httpfoundation-bridge
  3. Setup your database and run the provided migration (see

    php artisan db:migrate

  4. Seed your database using the provided script :

    php artisan db:seed

  5. Setup your OAuth2 server. To be able to access the single instance anywhere in your Laravel app, you can attach it as a singleton:
App::singleton('oauth2', function() {
    $storage = new OAuth2\Storage\Pdo(App::make('db')->getPdo());
    $server = new OAuth2\Server($storage);
    $server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));
    $server->addGrantType(new OAuth2\GrantType\UserCredentials($storage));
    return $server;
  1. Implement the actual OAuth2 controllers you wish to implement. For example a token controller and a resource controller: see app/routes.php

You can even unit test your integration! Here’s an example using Guzzle:

Fork me on GitHub