Skip to content

Commit

Permalink
Login a user for api tokens middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
nWidart committed Sep 16, 2017
1 parent 74bc58b commit eea48e3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Modules/User/Http/Middleware/AuthorisedApiToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\User\Contracts\Authentication;
use Modules\User\Repositories\UserTokenRepository;

class AuthorisedApiToken
Expand All @@ -12,10 +13,15 @@ class AuthorisedApiToken
* @var UserTokenRepository
*/
private $userToken;
/**
* @var Authentication
*/
private $auth;

public function __construct(UserTokenRepository $userToken)
public function __construct(UserTokenRepository $userToken, Authentication $auth)
{
$this->userToken = $userToken;
$this->auth = $auth;
}

public function handle(Request $request, \Closure $next)
Expand All @@ -35,6 +41,8 @@ private function isValidToken($token)
{
$found = $this->userToken->findByAttributes(['access_token' => $this->parseToken($token)]);

$this->auth->logUserIn($found->user);

if ($found === null) {
return false;
}
Expand Down

0 comments on commit eea48e3

Please sign in to comment.