Authenticate api requests

This commit is contained in:
Joseph Cohen 2015-05-20 17:01:26 -05:00
parent af69c99896
commit 78b7dc92d6
2 changed files with 23 additions and 3 deletions

View File

@ -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.',

View File

@ -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)
{