Thursday, March 9, 2017

API login from android app using laravel 5.3 passport

For two days I am digging google but could not find the starting thread for my problem, now I am out of option. Please help me with some direction/howTo

I have a web application running built with laravel 5.3, I have installed passport as described here . if I go /home its showing perfectly.

Home page

Now I have to make an android app from which

  1. An already existing user of web app can login
  2. get all the task list of that user TaskModel (ons_tasks(id, title, description))

routes related only

in web.php 
Auth::routes();

in api.php 

Route::get('/user', function (Request $request) {
    return $request->user();
})->middleware('auth:api');


Route::group(['middleware' => ['auth:api']], function () {

    Route::get('/test', function (Request $request) {
        return response()->json(['name' => 'test']);
    });

    Route::get('/task/list', function (Request $request) {        
        $list = \App\Model\TaskModel::all();
        return response()->json($list);
    });

});

To login : if I send post request /login with email & password get the TokenMismatchException error but Where do I obtain a token for android app in mobile? Do I need the Auth::routes() in the api too? if then what else Do I need to just login and get a token so later I can send it for geting the task lists.

Secondly,

If I go to /api/test it redirects me to /homepage without showning any error !!!

Thanks in advance.



via Atiqur

Advertisement