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.

40 lines
1.1 KiB

2 years ago
  1. <?php
  2. namespace App\Providers;
  3. use App\Documents\FingerPrintDocument;
  4. use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Auth;
  7. class AuthServiceProvider extends ServiceProvider
  8. {
  9. /**
  10. * The model to policy mappings for the application.
  11. *
  12. * @var array<class-string, class-string>
  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. Auth::viaRequest('token', function (Request $request) {
  26. if ($request->bearerToken() === null) {
  27. return null;
  28. }
  29. // you can change this line base on service you are on.
  30. $fingerPrint = FingerPrintDocument::where('token', $request->bearerToken())->with('user')->first();
  31. return empty($fingerPrint) ? null : $fingerPrint->user;
  32. });
  33. //
  34. }
  35. }