dcblogdev / laravel-dropbox

A Laravel package for working with Dropbox API v2.
Other
24 stars 18 forks source link

Single token per application #8

Open dancingfire opened 3 years ago

dancingfire commented 3 years ago

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...

rabol commented 3 years ago

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

generate your key in the Drop box console add

DROPBOX_ACCESS_TOKEN=

to your .env

dancingfire commented 3 years ago

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.

rabol commented 3 years ago

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 commented 3 years ago

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);
    }