Example #1
0
Autoloader::map(array(
// Required models. Feel free to mock those 
"SebRenauld\OAuth2\Models\Scope" => dirname(__FILE__).DS."models".DS."scope.php",
"SebRenauld\OAuth2\Models\Client" => dirname(__FILE__).DS."models".DS."client.php",
"SebRenauld\OAuth2\Models\Token" => dirname(__FILE__).DS."models".DS."token.php",

// The actual library 
"SebRenauld\OAuth2" => dirname(__FILE__).DS."libraries".DS."oauth2.php"
));
*/
Route::filter("oauth2", function () {
    $t = Input::get("oauth_token");
    if (!$t) {
        return Response::error(403);
    }
    if (($r = SebRenauld\OAuth2::verify($t)) === false) {
        return Response::error(403);
    }
});
Event::listen("oauth2.error.json", function ($r, $code) {
    $c = explode(":", $code);
    $msg = array_pop($c);
    if (count($c)) {
        $statusCode = array_pop($c);
    } else {
        $statusCode = 200;
    }
    return Response::json(json_encode(array('error' => $msg)), $statusCode);
});
Event::listen("oauth2.error.redirect", function ($uri, $code) {
    $new_uri = $uri;