spatie / flysystem-dropbox

A flysystem driver for Dropbox that uses the v2 API
https://freek.dev/734-dropbox-will-turn-off-v1-of-their-api-soon-its-time-to-update-your-php-application
MIT License
343 stars 50 forks source link

SSL certificate problem #14

Closed furey closed 7 years ago

furey commented 7 years ago

Hi! 👋

As always, another wonderful package from Spatie.

I thought I'd write up the following issue to help anyone who encounters it too.

While trying to get the package up and running on my local machine, on calling the put() method, the following exception was being thrown:

GuzzleHttp\Exception\RequestException with message 'cURL error 60: SSL certificate problem: Invalid certificate chain (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)'

To work around the exception, in DropboxServiceProvider, I simply instantiated and passed through my own GuzzleHttp\Client dependency with verify request option set to false:

<?php

namespace App\Providers;

use Storage;
use GuzzleHttp\Client as GuzzleClient;
use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client as DropboxClient;
use Illuminate\Support\ServiceProvider;
use Spatie\FlysystemDropbox\DropboxAdapter;

class DropboxServiceProvider extends ServiceProvider
{
    /**
     * Perform post-registration booting of services.
     */
    public function boot()
    {
        Storage::extend('dropbox', function ($app, $config) {

            $accessToken = $config['accessToken'];

            $guzzleClient = new GuzzleClient([
                'headers' => [
                    'Authorization' => "Bearer {$accessToken}",
                ],
                'verify' => false,
            ]);

            $client = new DropboxClient($accessToken, $guzzleClient);

            return new Filesystem(new DropboxAdapter($client));

        });
    }

    /**
     * Register bindings in the container.
     */
    public function register() {}
}

Note: Guzzle's documentation mentions disabling certificate verification (setting the verify request option to false) is insecure, and thus, should probably be used with caution.

Hope this information helps someone else down the track.

Cheers!