I'm currently implementing a token based authentication system in my API. This was build by Tappleby and it's installed in the Vendor folder of my Laravel installation. This works great as a filter. However, I need some functions of the package in my controller. I added use Tappleby\AuthToken\AuthToken;
to the controller and added the necessary lines to __construct
. That doesn't work though, because I keep getting Class AuthTokenDriver does not exist
.
Is that because the file is in the Vendor folder? Below you can see the controller, but please not that Tappleby\AuthToken\Exceptions\NotAuthorizedException
is located in the Vendor folder.
use Illuminate\Events\Dispatcher;
use Tappleby\AuthToken\Exceptions\NotAuthorizedException;
class ApiUsersController extends ApiController {
/**
* @var Acme\Transformers\UserTransformer
*/
protected $UserTransformer;
/**
* The event dispatcher instance.
*
* @var \Illuminate\Events\Dispatcher
*/
protected $events;
/**
* @var \Tappleby\AuthToken\AuthTokenDriver
*/
protected $driver;
function __construct(UserTransformer $userTransformer, UserLessonsTransformer $userLessonssTransformer, AuthTokenDriver $driver, Dispatcher $events)
{
$this->UserTransformer = $userTransformer;
$this->UserLessonTransformer = $userLessonTransformer;
$this->driver = $driver;
$this->events = $events;
}
public function index()
{
$payload = Request::header('X-Auth-Token');
if(empty($payload)) {
return $this->respondNotFound('User does not exist.');
}
$user = $this->driver->validate($payload);
return $payload;
}