123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace App\Providers;
- use App\Models\AppSession;
- use Illuminate\Support\Facades\Gate;
- use Laravel\Telescope\IncomingEntry;
- use Laravel\Telescope\Telescope;
- use Laravel\Telescope\TelescopeApplicationServiceProvider;
- class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
- {
- /**
- * Register any application services.
- *
- * @return void
- */
- public function register()
- {
- // Telescope::night();
- $this->hideSensitiveRequestDetails();
- Telescope::filter(function (IncomingEntry $entry) {
- // if ($this->app->environment('local')) {
- // return true;
- // }
- return true;
- return $entry->isReportableException() ||
- $entry->isFailedRequest() ||
- $entry->isFailedJob() ||
- $entry->isScheduledTask() ||
- $entry->hasMonitoredTag();
- });
- }
- /**
- * Prevent sensitive request details from being logged by Telescope.
- *
- * @return void
- */
- protected function hideSensitiveRequestDetails()
- {
- if ($this->app->environment('local')) {
- return;
- }
- Telescope::hideRequestParameters(['_token']);
- Telescope::hideRequestHeaders([
- 'cookie',
- 'x-csrf-token',
- 'x-xsrf-token',
- ]);
- }
- /**
- * Register the Telescope gate.
- *
- * This gate determines who can access Telescope in non-local environments.
- *
- * @return void
- */
- // protected function gate()
- // {
- // Gate::define('viewTelescope', function ($user) {
- // $sessionKey = request()->cookie('sessionKey');
- // $appSession = AppSession::where('session_key', $sessionKey)->where('is_active', true)->first();
- // $authenticated = $sessionKey && $appSession && $appSession->pro && $appSession->pro->pro_type == 'ADMIN';
- // if (!$authenticated) {
- // //return redirect('/');
- // return abort(403);
- // }
- // return false;
- //
- //
- // });
- // }
- //
- protected function authorization()
- {
- $this->gate();
- Telescope::auth(function ($request) {
- $sessionKey = request()->cookie('sessionKey');
- $appSession = AppSession::where('session_key', $sessionKey)->where('is_active', true)->first();
- $authenticated = $sessionKey && $appSession && $appSession->pro && $appSession->pro->pro_type == 'ADMIN';
- if (!$authenticated) {
- return abort(403);
- }
- return true;
- });
- }
- }
|