Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Can someone show a working sample of the new REST auth method
  • I saw in upgrading to 1.6 that REST was rebuilt to have internal auth checks. Before I would just do some work around logic in the router controller but from what I read you can set a method internally that should return a bool value? I can't get the response to here is a simplified example of a rest controller


    I can't seem to get the auth method to do anything


  • Code looks fine.

    Your warden() method should return:
    - true in case authentication succeeded
    - false in case authentication failed
    - a Reponse object if you want to return a custom response at failure
  • Yeah I keep getting {"status":0,"error":"Not Authorized"} regardless of the auth method

    public function warden()
    {
    \Log::debug('running auth check');
    return true;
    }

    So I'm missing something
  • And you're sure your method is called?
  • yeah I can see it in the log, would the before() and after() methods change anything?
  • check out this code, I'm basically pulling it from the docs with an added auth method

    class Controller_Test extends Controller_Rest
    {

          protected $format = 'json';
          protected $auth = 'warden';

          public function before()
          {
                parent::before();
          }

          protected function warden()
          {
                echo "Running auth check";
                return true;
          }

          public function get_list()
          {
                return $this->response(array(
                                'foo' => Input::get('foo'),
                                'baz' => array(
                                    1, 50, 219
                                ),
                                'empty' => null
                ));
          }

    }
  • HarroHarro
    Accepted Answer
    Can you check line 128 of Controller_Rest:

    if ($valid_login = $this->{$this->auth}() instanceOf \Response)

    and change it to

    if (($valid_login = $this->{$this->auth}()) instanceOf \Response)

    and see if that fixes it?
  • Yup that did it.

    I've never knew you could call a method like that
  • Cool. I've already committed it as a fix.
  • I was experiencing this in 1.7.1 - the above fixed it!

    Was the fix not rolled in to the main release?
  • It was committed on July 7th 2013. Which means it was part of the 1.7 release, and 1.7.1. has it too. I double checked the code in the zip, and it does.

    So there must have been something fishy about your install?
  • My bad - the code I'm working on is an older 1.6 release! I'm working on a couple of projects, most being 1.7.1. Sorry for the trouble!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion