Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter REST Server Authorization Not Working
#1

[eluser]imohammad[/eluser]
Well, I've spent quite a few hours trying to figure my silly problem.

I'm using REST Server and ClientREST by [Phil Sturgeo][1]


[1]: https://github.com/philsturgeon/codeigniter-restclient

My problem is that either I set the authorization to `basic` or `digest` it just doesn't authorise any thing on MAMP local host. The POST or GET just works fine!!

I've even tried CURL and regardless of having an authorization header that contains the API username and password, the call will just work and it will output the data for me.

Any thoughts?


REST.php

Code:
/*
    |--------------------------------------------------------------------------
    | REST Login
    |--------------------------------------------------------------------------
    |
    | Is login required and if so, which type of login?
    |
    | '' = no login required, 'basic' = unsecure login, 'digest' = more secure login,
    | 'session' = check for PHP session variable. Set variable name below.
    |
    */
    $config['rest_auth'] = 'basic';
    
    /*
    |--------------------------------------------------------------------------
    | REST Login
    |--------------------------------------------------------------------------
    |
    | Is login required and if so, which user store do we use?
    |
    | '' = use config based users, 'ldap' = use LDAP authencation, 'library' = use a authentication library
    | If 'rest_auth' is 'session' then set 'auth_source' to the name of the session variable to check for.
    |
    */
    $config['auth_source'] = '';
    
    /*
    |--------------------------------------------------------------------------
    | REST Login usernames
    |--------------------------------------------------------------------------
    |
    | Array of usernames and passwords for login, if ldap is configured this is ignored
    |
    | array('admin' => '1234')
    |
    */
    $config['rest_valid_logins'] = array('admin' => '1234');

My Controller

Code:
class Test extends Base_Controller {
    
        public function index()
        {
            // $this->load->model('roles/role_model');
            // $role = $this->role_model->find(1);
    
            //die('<pre>'. print_r($role, true));
            
            $this->load->spark('restclient/2.2.1');
    
            $config = array('server'            => base_url().'api/users',
                            'http_user'       => 'admin',
                            'http_pass'       => '12dd34',
                            'http_auth'       => 'basic',
                            );
    
            $this->rest->initialize($config);
            $user = $this->rest->get('show/id/1', array(), 'json');
            
            $this->rest->debug();      
        }
    
        //--------------------------------------------------------------------
    
    }

My API ( Note I'm using DataMapper here)

Code:
public function show_get()
    {
    
        if(!$this->get('id') AND !$this->get('username'))
        {
         $this->response(array('status'=>'error'), 400);
        }
    
        $user = new User();
    
        switch ( $this->uri->segment(4) )
        {
         case 'id':
          $user->get_by_id($this->get('id'));  
          $this->response($user->to_array(), 200);
          break;
        
         case 'username':
          $user->get_by_username($this->get('username'));  
          $this->response($user->to_array(), 200);
          break;
    
         default:
          $this->response(array('error' => 'User could not be found'), 400);
          break;
        }
    
     // $user = @$users[$this->get('id')];
    }
#2

[eluser]imohammad[/eluser]
40 views and no reply, clearly I'm doing something wrong?
#3

[eluser]ivantcholakov[/eluser]
I would check first whether Curl, Rest Client and Rest Server libraries are in their latest versions. Maybe it is a known problem that has already been solved. Especially the Rest Server has a lot of changes.

https://github.com/philsturgeon/codeigniter-curl
https://github.com/philsturgeon/codeigniter-restclient
https://github.com/chriskacerguis/codeig...restserver




Theme © iAndrew 2016 - Forum software by © MyBB