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?

4
  • Matt Stauffer had written an excellent tutorial on laravel/passport, which should help you out: mattstauffer.co/blog/introducing-laravel-passport
    – craig_h
    Oct 26, 2016 at 8: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? Oct 26, 2016 at 9: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, 2016 at 6: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, 2017 at 22:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.