22

How to authenticate RESTful API in Laravel 5? I am using Laravel 5 to build a RESTful API & I want to use those API for mobile application.

I have also seen http://laravel.com/docs/5.0/authentication but not getting any related example so,please provide me sample example or appropriate link for authenticate RESTful API in Laravel 5.

Vaibhav
  • 325
  • 1
  • 2
  • 10

2 Answers2

17

I was looking for the same answer and I found this link very useful with detailed information and usage for L5 with the use of JWT .

JSON Web Token

Hope it helps you too.

Tarunn
  • 1,038
  • 3
  • 23
  • 45
5

The Concept to use here would be Middleware: To get you started, put this in your API-Controller's ctors:

public function __construct()
{
    // reqires Authentificataion before access
    $this->middleware('auth.basic');
}

Your app should then be able to call the resources like

http://user:pass@yourapp.com/yourresource/1
nozzleman
  • 9,529
  • 4
  • 37
  • 58
  • 1
    I want to authenticate my API only once or using authentication token – Vaibhav Mar 03 '15 at 12:22
  • in this case, you would have to write your own middleware. Laravel only provies a hand full of middlewares out of the box. see https://github.com/laravel/laravel/blob/master/app/Http/Kernel.php Writing your own isn't that hard, see https://mattstauffer.co/blog/laravel-5.0-middleware-filter-style or the laravel docs – nozzleman Mar 03 '15 at 12:34
  • since i am using this construct, i dont have one right now. it also depends on your 'authentication token'. – nozzleman Mar 04 '15 at 08:50