laravel-dropbox icon indicating copy to clipboard operation
laravel-dropbox copied to clipboard

Single token per application

Open dancingfire opened this issue 4 years ago • 4 comments

Not sure how best to go about asking this question so I'll ask it here. First off tho, thanks for your work on this project.

I'm using this system to talk to Dropbox on behalf of an entire application. When using the token method to setup communication with Dropbox, the Auth:User is used to store the token. I only need one, so I'd like to override this once for the entire app. I could fork the code and change a few lines of code, but wondering if this is already handled in some other way? If not, would it be useful for me to submit a pull whereby there's a new config settings that is the AuthID to be used, and if this is set, that is used instead of the AuthID?

I'm not very familiar with the process of contributing to open source projects...

dancingfire avatar May 07 '21 13:05 dancingfire

https://dcblog.dev/docs/laravel-dropbox/introduction/install

generate your key in the Drop box console add

DROPBOX_ACCESS_TOKEN=

to your .env

rabol avatar Jun 21 '21 09:06 rabol

Thanks - my understanding is that Dropbox is turning off the long-term identity tokens that this method relies on, so I was angling for a way that short term tokens could be renewed for a specific userID, not for the userID of the person who is logged in. Same as the above approach, but there would be a DROPBOX_TOKEN_USER_ID that would be set to an existing user of the application and always used for the Dropbox login, no matter which actual user was logged in.

dancingfire avatar Jun 21 '21 12:06 dancingfire

Yes, Dropbox is dropping long terms tokens, but... I believe that this package uses the 'refresh_token' identity to renew the short-live token, but...

there is either some documentation missing or the 'refresh' feature does not work

e.g Dropbox::isConnected() returns true, but then if you try to access folders Dropbox throws an error saying that the token has expired.

I'm trying to figure out how it should work as I need the 'auto-refresh' in my app

rabol avatar Jun 23 '21 09:06 rabol

I think this is working :)

In a controller:

    public function index()
    {
        if (!Dropbox::isConnected()) {
            return redirect(config('dropbox.redirectUri'));
        } else {
            $token = Dropbox::getTokenData();
            $date = new Carbon;
            if($date > $token->expires_in) {
                if(is_null(Dropbox::getAccessToken()))
                {
                    return redirect(config('dropbox.redirectUri'));
                }
            }
        }

        //display user details
        $user_data = Dropbox::post('users/get_current_account');
        return view('empty')->with('userdata', $user_data);
    }

rabol avatar Jun 23 '21 10:06 rabol