You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Providers;
  3. use App\Fingerprint;
  4. use App\Utilities\RequestMixin;
  5. use App\Utilities\BusinessInfoRequestMixin;
  6. use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
  7. class AuthServiceProvider extends ServiceProvider
  8. {
  9. /**
  10. * The policy mappings for the application.
  11. *
  12. * @var array
  13. */
  14. protected $policies = [
  15. // 'App\Models\Model' => 'App\Policies\ModelPolicy',
  16. ];
  17. /**
  18. * Register any authentication / authorization services.
  19. *
  20. * @return void
  21. */
  22. public function boot()
  23. {
  24. $this->registerPolicies();
  25. $this->app['request']->mixin(new RequestMixin);
  26. $this->app['request']->mixin(new BusinessInfoRequestMixin);
  27. $this->app['auth']->viaRequest('api', function ($request) {
  28. if ($request->bearerToken() === null) {
  29. return null;
  30. }
  31. $fingerprint = Fingerprint::where([
  32. 'token' => $request->bearerToken(),
  33. 'agent' => $request->getAgent(),
  34. 'os' => $request->getOS(),
  35. ])->first();
  36. return $fingerprint->user->setAttribute('token', $fingerprint->token);
  37. });
  38. }
  39. }