Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Telescope - 403 Forbidden

I have implemented Laravel Telescope and I can only acces if APP_ENV=local

I have followed Laravel's documentation and I changed code in TelescopeServiceProvider.php (take in care that my evironments are called loca, dev, testing and prod).

The only way I can access Telescope is changing APP_ENV=local in each enviroment.

Does anyone knows which can be by issue?

Regards

<?php

namespace App\Providers;

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') || $this->app->environment('dev') || $this->app->environment('test') || $this->app->environment('prod')) {
                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') || $this->app->environment('dev') || $this->app->environment('test') || $this->app->environment('prod')) {
            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) {
            return in_array($user->email, [
                //
            ]);
        });
    }
}

This is my confif/app.php file

/*
 * Application Service Providers...
 */
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
//App\Providers\TelescopeServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Laravel\Socialite\SocialiteServiceProvider::class,
like image 373
Belisario Peró Avatar asked Mar 17 '20 23:03

Belisario Peró


People also ask

What is telescope in Laravel?

Laravel Telescope makes a wonderful companion to your local Laravel development environment. Telescope provides insight into the requests coming into your application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps, and more.

How to fix the Forbidden error page in Laravel?

This caused the Forbidden error page. Restarting the web server allowed proper Whoops! error to display: Route [my-route-name] not defined. Fixing the route name ->name ('my-route-name') fixed the error. This is on Laravel 5.5 & using wampserver.

Why is my website showing 403 Forbidden error?

Sometimes, some route showing 403 forbidden error and whole website working fine. it’s occure due to same route name already available in public folder. you have to write different route name or folder name in public folder.

How to point to your Laravel application from your virtualhost?

In your VirtualHost write the DocumentRoot to point to your Laravel Application in your home directories. In addition you must add the Directory shown below, with your own path:


2 Answers

By default, you will only be able to access this dashboard in the local environment.

Within your app/Providers/TelescopeServiceProvider.php file, there is a gate method. This authorization gate controls access to Telescope in non-local environments. You are free to modify this gate as needed to restrict access to your Telescope installation:

/**
 * 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) {
        return in_array($user->email, [
            // Your users
            '[email protected]',
        ]);
    });
}
like image 62
Wahyu Kristianto Avatar answered Sep 28 '22 07:09

Wahyu Kristianto


You may override authorization() method in Laravel\Telescope\TelescopeApplicationServiceProvider in your App\Providers\TelescopeServiceProvider and include your enviroment name.

But be careful with it.

/**
 * Configure the Telescope authorization services.
 *
 * @return void
 */
protected function authorization()
{
    $this->gate();

    Telescope::auth(function ($request) {
        return app()->environment('local') ||
               Gate::check('viewTelescope', [$request->user()]);
    });
}

to

...
return app()->environment(['local', testing]) ||
       Gate::check('viewTelescope', [$request->user()]);
...
like image 30
Elnur Ibrahim-zade Avatar answered Sep 28 '22 09:09

Elnur Ibrahim-zade