AuthServiceProvider.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Providers;
  11. use App\Repositories\Enums\PermissionEnum;
  12. use Illuminate\Support\Facades\Gate;
  13. use Illuminate\Support\ServiceProvider;
  14. class AuthServiceProvider extends ServiceProvider
  15. {
  16. /**
  17. * Register any application services.
  18. */
  19. public function register()
  20. {
  21. }
  22. /**
  23. * Boot the authentication services for the application.
  24. */
  25. public function boot()
  26. {
  27. // Here you may define how you wish users to be authenticated for your Lumen
  28. // application. The callback which receives the incoming request instance
  29. // should return either a User instance or null. You're free to obtain
  30. // the User instance via an API token or any other method necessary.
  31. /*$this->app['auth']->viaRequest('api', function ($request) {
  32. if ($request->input('api_token')) {
  33. return User::where('api_token', $request->input('api_token'))->first();
  34. }
  35. });*/
  36. Gate::before(PermissionEnum::gateBeforeCallback());
  37. $this->app['auth']->provider('custom', function ($app, array $config) {
  38. return new EloquentUserProvider($app['hash'], $config['model']);
  39. });
  40. }
  41. }