AuthServiceProvider.php 1016B

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