api-guard icon indicating copy to clipboard operation
api-guard copied to clipboard

Extending ApiGuardController

Open cascornelissen opened this issue 8 years ago • 3 comments

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?

cascornelissen avatar Mar 29 '16 18:03 cascornelissen

@chrisbjr, any thoughts or updates on this?

cascornelissen avatar Apr 11 '16 17:04 cascornelissen

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.

morganzysman avatar May 04 '16 23:05 morganzysman

Same here.. Simply calling $apiMethods in the extended controller always return null

rmdwirizki avatar Jun 02 '16 08:06 rmdwirizki