Code Monkey home page Code Monkey logo

Comments (9)

freekmurze avatar freekmurze commented on June 1, 2024 1

Feel free to start, I highly appreciate a PR for this 👍

from flysystem-dropbox.

garrettboone avatar garrettboone commented on June 1, 2024

@freekmurze What would be the general approach/preference regarding where/how to store the new refresh tokens? Database? Local file?

from flysystem-dropbox.

freekmurze avatar freekmurze commented on June 1, 2024

Maybe make an interface so users can choose where to store stuff.

from flysystem-dropbox.

garrettboone avatar garrettboone commented on June 1, 2024

In my Laravel setup, I think I will work toward a local storage solution for the refresh token. I am using the CachedAdapter already so I could take an approach of an .env variable with the path.

DropboxServiceProvider.php
namespace App\Providers;

use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider;
use Spatie\Dropbox\Client as DropboxClient;
use League\Flysystem\Filesystem;
use Spatie\FlysystemDropbox\DropboxAdapter;
use League\Flysystem\Adapter\Local as CacheFilePath;
use League\Flysystem\Cached\CachedAdapter;
use League\Flysystem\Cached\Storage\Adapter as CustomAdapter;

class DropboxServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Storage::extend('dropbox', function ($app, $config) {
            $client = new DropboxClient($config['authorization_token']);
            $dropbox = new DropboxAdapter($client);
            $local = new CacheFilePath('/mnt/secure_files/dropbox');
            $cache = new CustomAdapter($local, 'cachefile', 300);
            $adapter = new CachedAdapter($dropbox, $cache);
            return new Filesystem($adapter, ['case_sensitive' => false]);
        });
    }
}

My server is not publicly accessible, and I would be using the offline (long-lived) refresh token. I just went through rclone's process for the same thing on a Debian server.

I'm thinking I could follow the approach rclone took and create a Console configuration script which would allow (as in my case on a server with no public access) a URL to be copied, and taken to a device with internet access to get the initial response code. Then the code gets entered, and first refresh token gets stored.

With that, and adding in logic to incorporate the refresh token process, and adding a catch for the 401 Unauthorized response (which would then require the user to run configuration again), I think that might work. In Client.php where there is a check for the $accessTokenOrAppCredentials I could incorporate a check for whether the REFRESH_TOKEN_PATH is empty. If it's not, then proceed with using that.

How does this sound?

from flysystem-dropbox.

garrettboone avatar garrettboone commented on June 1, 2024

I see there is a discussion in dropbox-api which handles credentials. Sorry this was the wrong place.

from flysystem-dropbox.

anderea1 avatar anderea1 commented on June 1, 2024

@garrettboone Hi, did you manage to add short-lived token functionality? Thanks

from flysystem-dropbox.

garrettboone avatar garrettboone commented on June 1, 2024

@anderea1 No, I've been putting it off so my files are piling up in a temp folder. It seems everyone else is going for a end-user interface with oauth2 but I don't need that. If you think you want to do it, go for it. But if not, let me know. I need it myself and should do something soon.

from flysystem-dropbox.

anderea1 avatar anderea1 commented on June 1, 2024

@garrettboone see here if it suits you #86

from flysystem-dropbox.

garrettboone avatar garrettboone commented on June 1, 2024

@anderea1 With long-lived refresh tokens, even though they are long-lived they are part of each response and can be replaced. ie long-lived but short-used. By storing it locally and replacing each request rather than noting in the env, as long as a request is made frequently enough, you won't run into an expired refresh token.

from flysystem-dropbox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.