1 |
54fa168c
|
Cajova-Houba
|
<?php
|
2 |
|
|
|
3 |
|
|
namespace App\Providers;
|
4 |
|
|
|
5 |
|
|
use App\User;
|
6 |
cb15593b
|
Cajova-Houba
|
use Illuminate\Support\Facades\Auth;
|
7 |
54fa168c
|
Cajova-Houba
|
use Illuminate\Support\Facades\Gate;
|
8 |
|
|
use Illuminate\Support\ServiceProvider;
|
9 |
|
|
|
10 |
|
|
class AuthServiceProvider extends ServiceProvider
|
11 |
|
|
{
|
12 |
|
|
/**
|
13 |
|
|
* Register any application services.
|
14 |
|
|
*
|
15 |
|
|
* @return void
|
16 |
|
|
*/
|
17 |
|
|
public function register()
|
18 |
|
|
{
|
19 |
|
|
//
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
/**
|
23 |
|
|
* Boot the authentication services for the application.
|
24 |
|
|
*
|
25 |
|
|
* @return void
|
26 |
|
|
*/
|
27 |
|
|
public function boot()
|
28 |
|
|
{
|
29 |
|
|
// Here you may define how you wish users to be authenticated for your Lumen
|
30 |
|
|
// application. The callback which receives the incoming request instance
|
31 |
|
|
// should return either a User instance or null. You're free to obtain
|
32 |
|
|
// the User instance via an API token or any other method necessary.
|
33 |
|
|
|
34 |
cb15593b
|
Cajova-Houba
|
Auth::viaRequest('api', function ($request) {
|
35 |
54fa168c
|
Cajova-Houba
|
if ($request->input('api_token')) {
|
36 |
|
|
return User::where('api_token', $request->input('api_token'))->first();
|
37 |
|
|
}
|
38 |
|
|
});
|
39 |
|
|
}
|
40 |
|
|
}
|