From 78b7dc92d65cd544af5f99aaba3a90bd1873493e Mon Sep 17 00:00:00 2001 From: Joseph Cohen Date: Wed, 20 May 2015 17:01:26 -0500 Subject: [PATCH] Authenticate api requests --- app/Http/Middleware/ApiAuthenticate.php | 22 +++++++++++++++++++++- app/Http/Middleware/Authenticate.php | 4 ++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/Http/Middleware/ApiAuthenticate.php b/app/Http/Middleware/ApiAuthenticate.php index 425be91a..236cc97c 100644 --- a/app/Http/Middleware/ApiAuthenticate.php +++ b/app/Http/Middleware/ApiAuthenticate.php @@ -15,10 +15,28 @@ namespace CachetHQ\Cachet\Http\Middleware; use CachetHQ\Cachet\Models\User; use Closure; +use Illuminate\Contracts\Auth\Guard; use Illuminate\Database\Eloquent\ModelNotFoundException; class ApiAuthenticate { + /** + * The Guard implementation. + * + * @var \Illuminate\Contracts\Auth\Guard + */ + protected $auth; + + /** + * Create a new filter instance. + * + * @param \Illuminate\Contracts\Auth\Guard $auth + */ + public function __construct(Guard $auth) + { + $this->auth = $auth; + } + /** * Handle an incoming request. * @@ -31,7 +49,9 @@ class ApiAuthenticate { if ($apiToken = $request->header('X-Cachet-Token')) { try { - User::findByApiToken($apiToken); + $user = User::findByApiToken($apiToken); + + $this->auth->onceUsingId($user->id); } catch (ModelNotFoundException $e) { return response()->json([ 'message' => 'The API token you provided was not correct.', diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 5bdb738c..1f93b221 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -21,14 +21,14 @@ class Authenticate /** * The Guard implementation. * - * @var Guard + * @var \Illuminate\Contracts\Auth\Guard */ protected $auth; /** * Create a new filter instance. * - * @param Guard $auth + * @param \Illuminate\Contracts\Auth\Guard $auth */ public function __construct(Guard $auth) {