0

I'm building an application that post data from Android device to cakephp backend (Web Service). I ended up with making my own authentication object and sending access token like this :

class MyAuthenticate extends BaseAuthenticate {

    public function authenticate(CakeRequest $request, CakeResponse $response) {

        $userCont = $this->_Collection->getController();
        $userCont->loadModel($this->_Collection->getController()->modelClass);

        $response = array();


        if (isset($request['data']['access_token']) AND $userCont->User->find('all', array('recursive' => 0, 'conditions' => array('User.access_token' => $request['data']['access_token'])))) {

            //debug( $userCont->User->find('all',array('recursive'=>0,'conditions'=>array('access_token'=>$request['data']['access_token'])))); 
            //die;
            return $userCont->User->find('all', array('recursive' => 0, 'conditions' => array('access_token' => $request['data']['access_token'])));
        }
        else
            return false;//print_r('NOT FOUND');
     } 

And then added this to authentication array

public function beforeFilter() {


    $this->Auth->authenticate = array(
        AuthComponent::ALL => array('userModel' => 'User'),

        'Form',
        'My'


    );

I test it by posting a request with access token to the login page and this returns back the home page (the redirect url).

Now I want to post data to other controller action like "add" post. If I sent the request to for example mysite/posts/add with the access token and the request params, it does not post and returns back the ACL permission error message.

I think I need to make some redirect or make manual redirect in the login or some thing ?. Is my logic correct till now in building this authentication object ?

Thanks a lot.

1 Answers1

0

You can use $this->Auth->allow('..ACTION..') in your controller. You'll now have to check the header of the request in your Cake-handling now, so I'd recommend creating a seperate WebserviceController with this check in the beforeFilter method...

  • Create a controller called WebserviceController and set the following variables on the top, like the next code: '' var $helpers = array('Html','Ajax','Javascript'); var $components = array( 'RequestHandler' ); function beforeFilter(){ $this->Auth->allow('service1action', 'etc..'); parent::beforeFilter(); } ''' – Erik Blanken Apr 11 '13 at 23:20