api-guard
api-guard copied to clipboard
Extending ApiGuardController
I'm trying to extend the ApiGuardController
to allow for disabling the feature during development (based on APP_DEBUG
) and "global" request limiting. It works just fine but I'm thinking about features that will be executed based on the validity of the key (e.g. e-mail notifications) but ApiGuardAuth::isAuthenticated()
always returns false.
I'm extending the following custom controller in my own controllers.
<?php
namespace App\Http\Controllers;
use \Chrisbjr\ApiGuard\Http\Controllers\ApiGuardController;
use Config;
use ApiGuardAuth;
class ApiController extends ApiGuardController {
protected $apiMethods;
public function __construct() {
// Disable API key authentication on development environments
if ( !env('APP_DEBUG') ) {
parent::__construct();
$this->apiMethods = Config::get('api.api-guard');
// var_dump(ApiGuardAuth::isAuthenticated());
}
}
}
Why is it returning false and what would be the best way to determine whether the current request has a valid key?
Another (probably relevant) question I'm having is how to change the error object (GEN-UNAUTHORIZED
a.o.) that gets returned?
@chrisbjr, any thoughts or updates on this?
I'm interested in doing that too. I has doing class ApiController extends ApiGuardController with the version two without any problem.
I'm now working on a new projet, and I'm not able to use $this->user when extending ApiGuardController nor the apiMethodes seem to be working.
Same here.. Simply calling $apiMethods in the extended controller always return null