Notification texts go here Contact Us Buy Now!

Laravel Telescope - 403 Forbidden

In Laravel Telescope, by default, only the local environment is allowed to access the dashboard. To modify this restriction in non-local environments, you can edit the gate method within the app/Providers/TelescopeServiceProvider.php file.

Here's an example of how you can modify the gate method to control access:

/**
   * 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
              'user@yourapp.tld',
          ]);
      });
  }

This will restrict access to Telescope to only the users whose email addresses are included in the array.

Alternatively, you can override the authorization() method in Laravel\Telescope\TelescopeApplicationServiceProvider within your App\Providers\TelescopeServiceProvider.

Note: Be cautious when making changes to the authorization methods, as it can compromise the security of your Telescope installation.

/**
   * 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()]);
      });
  }

By changing the app()->environment() condition to include your desired environment, you can allow access to Telescope in specific non-local environments.

For API applications, you can use cookie-based authentication. Add the secretTelescope cookie secret and run the following code:

Gate::define('viewTelescope', function (?User $user) {
      return array_key_exists('secretTelescope', $_COOKIE);
  );

Remember to set the TELESCOPE_ENABLED environment variable to true and ensure that the APP_ENV is set to local or your desired environment.

These modifications should allow you to control access to the Laravel Telescope dashboard in various environments based on your specific requirements.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.