4

I have installed Passport Auth in Laravel 5.3 using this documentation https://laravel.com/docs/master/passport

but I have followed the steps before "Frontend Quickstart" heading now I have a API route:

Route::get('/user', function (Request $request) {
    //return $request->user();
    return json_encode(array(
      1 => "John",
      2 => "Mary",
      3 => "Steven"
    ));
})->middleware('auth:api');

and I am trying to hit api url via postman http://localhost/project/public/api/user

with Headers: Accept: application/json

It shows me this output:

{"error":"Unauthenticated."}

Please tell me how I can authenticate my API with passport auth? Also how I can generate access_token for authorization?

okconfused
  • 3,567
  • 4
  • 25
  • 38
  • Matt Stauffer had written an excellent tutorial on `laravel/passport`, which should help you out: https://mattstauffer.co/blog/introducing-laravel-passport – craig_h Oct 26 '16 at 08:44
  • `access_token` generation depends in where do you want to use your API. A third application will have access to your API? An user will have access to your API? If that is the case, this user is registered in the Laravel API application database or in a third application database? – Gerard Reches Oct 26 '16 at 09:21
  • 1
    @craig_h, can you tell me how I can generate client_id and client_secret in the passport auth without Vue component? because without client_id and client_secret how I can authenticate users to access API – okconfused Oct 27 '16 at 06:14
  • I realize this is very old, but hit this upon googling. So, here's the answer to your last comment, in case anyone else lands here from the big G: `php artisan passport:client --password` – S.A Sep 12 '17 at 22:08

0 Answers0