Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation question: Auth never fires #33

Closed
jklegseth opened this issue Mar 30, 2015 · 2 comments
Closed

Implementation question: Auth never fires #33

jklegseth opened this issue Mar 30, 2015 · 2 comments

Comments

@jklegseth
Copy link

This isn't an issue as much as a request for help. I couldn't find a forum where this would be better asked.

I'm using the package under Laravel 4.2.11. I've tried the most basic of examples but am unable to get the auth to do anything. This is a contrived example obviously and I wouldn't actually use POST to get books--I ultimately need to add new rows to a db. Anyway, changing to a GET makes no difference.

I have installed the package, done the migration and generated a key, and verified they exist.

My controller is:

<?php namespace App\Controllers;
use Chrisbjr\ApiGuard\Controllers\ApiGuardController;
use Response;
use Storage\Book\BookRepository as Book;

class BookController extends ApiGuardController {
  protected $book;

  public function __construct(
    Book $book
  ) {
    $this->book = $book;
  }

  public function postUpdateBooks() {
    return Response::json($this->book->getBooks());
  }
}

$this->book->getBooks() is a call to a model method that returns all books. I'm using the Response class as discussed in #19.

I then try this using curl (also using Postman):

curl -X POST https://localdev.com/api/v1/books

Rather than trigger an auth error, I get the books JSON return. If I add an incorrect X-Authorization token, I still get the books JSON. My understanding is all methods automatically have keyAuthentication enabled, but I still tried adding the protected $apiMethods property and set it to true. Still no auth.

I'm getting no errors and the api_logs table is empty. I'd appreciate any pointers.

@chrisbjr
Copy link
Owner

Hi @jklegseth

You have overridden the __construct() method. To prevent this please call parent::__construct() as follows:

<?php
namespace App\Controllers;
use Chrisbjr\ApiGuard\Controllers\ApiGuardController;
use Response;
use Storage\Book\BookRepository as Book;

class BookController extends ApiGuardController {

    protected $book;

    public function __construct($book)
    {
        parent::__construct();
        $this->book = $book;
    }

}

@jklegseth
Copy link
Author

Thanks @chrisbjr!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants