public function post_token() { $this->filter('before', 'oauth2'); $oauth = new OAuth2Server\Libraries\OAuth2(new OAuth2StorageLaravel()); try { $oauth->grantAccessToken(); } catch (OAuth2Server\Libraries\OAuth2ServerException $oauthError) { $oauthError->sendHttpResponse(); } }
/* |-------------------------------------------------------------------------- | Route Filters |-------------------------------------------------------------------------- */ Route::filter('before', function () { // Do stuff before every request to your application... }); Route::filter('after', function ($response) { // Do stuff after every request to your application... }); Route::filter('csrf', function () { if (Request::forged()) { return Response::error('500'); } }); Route::filter('auth', function () { if (Auth::guest()) { return Redirect::to('login')->with('backlink', URL::full()); } }); Route::filter('oauth2', function () { try { $oauth = new OAuth2Server\Libraries\OAuth2(new OAuth2StorageLaravel()); $token = $oauth->getBearerToken(); $verify = $oauth->verifyAccessToken($token); Auth::login($verify['user_id']); } catch (OAuth2Server\Libraries\OAuth2ServerException $oauthError) { $oauthError->sendHttpResponse(); } });