TelescopeServiceProvider.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace App\Providers;
  3. use App\Models\AppSession;
  4. use Illuminate\Support\Facades\Gate;
  5. use Laravel\Telescope\IncomingEntry;
  6. use Laravel\Telescope\Telescope;
  7. use Laravel\Telescope\TelescopeApplicationServiceProvider;
  8. class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
  9. {
  10. /**
  11. * Register any application services.
  12. *
  13. * @return void
  14. */
  15. public function register()
  16. {
  17. // Telescope::night();
  18. $this->hideSensitiveRequestDetails();
  19. Telescope::filter(function (IncomingEntry $entry) {
  20. if ($this->app->environment('local')) {
  21. return true;
  22. }
  23. return $entry->isReportableException() ||
  24. $entry->isFailedRequest() ||
  25. $entry->isFailedJob() ||
  26. $entry->isScheduledTask() ||
  27. $entry->hasMonitoredTag();
  28. });
  29. }
  30. /**
  31. * Prevent sensitive request details from being logged by Telescope.
  32. *
  33. * @return void
  34. */
  35. protected function hideSensitiveRequestDetails()
  36. {
  37. if ($this->app->environment('local')) {
  38. return;
  39. }
  40. Telescope::hideRequestParameters(['_token']);
  41. Telescope::hideRequestHeaders([
  42. 'cookie',
  43. 'x-csrf-token',
  44. 'x-xsrf-token',
  45. ]);
  46. }
  47. /**
  48. * Register the Telescope gate.
  49. *
  50. * This gate determines who can access Telescope in non-local environments.
  51. *
  52. * @return void
  53. */
  54. // protected function gate()
  55. // {
  56. // Gate::define('viewTelescope', function ($user) {
  57. // $sessionKey = request()->cookie('sessionKey');
  58. // $appSession = AppSession::where('session_key', $sessionKey)->where('is_active', true)->first();
  59. // $authenticated = $sessionKey && $appSession && $appSession->pro && $appSession->pro->pro_type == 'ADMIN';
  60. // if (!$authenticated) {
  61. // //return redirect('/');
  62. // return abort(403);
  63. // }
  64. // return false;
  65. //
  66. //
  67. // });
  68. // }
  69. //
  70. protected function authorization()
  71. {
  72. $this->gate();
  73. Telescope::auth(function ($request) {
  74. $sessionKey = request()->cookie('sessionKey');
  75. $appSession = AppSession::where('session_key', $sessionKey)->where('is_active', true)->first();
  76. $authenticated = $sessionKey && $appSession && $appSession->pro && $appSession->pro->pro_type == 'ADMIN';
  77. if (!$authenticated) {
  78. return abort(403);
  79. }
  80. return true;
  81. });
  82. }
  83. }