How to authenticate the user base on the response of an API call?

Description:

I have been using Laravel for a bunch of project now.
Implementing User Authentication is simple in Laravel. Now, the structure that I am dealing with is a little different – I don’t have a database or a users table locally. I have to make an API call to query what I need.


I’ve tried

public function postSignIn(){

    $username     = strtolower(Input::get('username'));
    $password_api = VSE::user('password',$username); // abc <-----
    $password     = Input::get('password'); // abc <-----


    if ( $password == $password_api ) {
        //Log user in
        $auth = Auth::attempt(); // Stuck here <----
    }

    if ($auth) {
      return Redirect::to('/dashboard')->with('success', 'Hi '. $username .' ! You have been successfully logged in.');
    }
    else {
      return Redirect::to('/')->with('error', 'Username/Password Wrong')->withInput(Request::except('password'))->with('username', $username);
    }
  }

Result:

I kept getting : Undefined index: password

enter image description here

Can I still use Laravel Class Auth to achieve the log-in feature ?

Can someone shed some lights on this ?


Updated (Base on @Bogdan request )

I connect to the API using a simple shell_exec command in my VSE class

public static function user($attr, $username) {

        $data = shell_exec('curl '.env('API_HOST').'vse/account/user/'.$username);
        $raw = json_decode($data,true);
        $array =  $raw['data'];
        return $array[$attr];
    }

I wish I can show that to you here, But it is on the VM on my local machine so please stay with me here. Basically, It

Execute

curl http://172.16.67.137:1234/vse/account/user/bob@xyzcorp.com

Response

Object
data:Object
DBA:""
account_id:111
account_type:"admin"
display_name:"BobJ"
email_address:"bob@xyzcorp.com"
first_name:"Bob"
last_name:"Jones"
password:"abc"
message:"Success"
status:200

As you can see the password is abc

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s