Code Monkey home page Code Monkey logo

Comments (7)

greg-db avatar greg-db commented on June 10, 2024

Dropbox is no longer offering the option for creating new long-lived access tokens. Dropbox is now issuing short-lived access tokens (and optional refresh tokens) instead of long-lived access tokens. You can find more information on this migration here.

Apps can still get long-term access by requesting "offline" access though, in which case the app receives a "refresh token" that can be used to retrieve new short-lived access tokens as needed, without further manual user intervention. You can find more information in the OAuth Guide and authorization documentation. There's a basic outline of processing this flow in this blog post which may serve as a useful example. Use of a redirect URI is not required, whether or not you're requesting a refresh token.

For examples of implementing this with the Dropbox JavaScript SDK, please refer to the examples included in the "examples" folder in the SDK. As long as you set the app key (a.k.a. client ID) and refresh token, like shown in this example for the JavaScript SDK, the SDK will actually handle refresh process for you automatically. The SDK will automatically catch expired access token errors and call the API to get a new short-lived access token when needed. Refresh tokens don't expire (though they can be revoked on demand), so it doesn't need to be replaced/updated each time; you can re-use the same refresh token repeatedly. So, if this is only for your own account, you would only need to get a refresh token for your own account once and could re-use that.

from dropbox-sdk-js.

Lioness100 avatar Lioness100 commented on June 10, 2024

Thanks, I didn't realize that refresh tokens didn't expire <3

from dropbox-sdk-js.

Lioness100 avatar Lioness100 commented on June 10, 2024

@greg-db I'm still having issues. Even though I provided both an access token and refresh token, I keep getting "expired_access_token". It works initially, but stops after a bit (I haven't measured how long)

from dropbox-sdk-js.

greg-db avatar greg-db commented on June 10, 2024

Please share the code you're running that isn't working as expected so we can take a look. Please redact the app secret and token values themselves though.

from dropbox-sdk-js.

Lioness100 avatar Lioness100 commented on June 10, 2024
const dbx = new Dropbox({
	accessToken: '...',
	refreshToken: '...',
	pathRoot: JSON.stringify({ '.tag': 'root', root: '...' }),
	selectUser: '...'
});

export const myFunc = async () => {
	// ...
	const { result } = await dbx.filesListFolder({ path, recursive: false });
	// ...
}

from dropbox-sdk-js.

greg-db avatar greg-db commented on June 10, 2024

The refresh process requires the app key (a.k.a. client ID), and if the refresh token wasn't retrieved using PKCE, the app secret (a.k.a. client secret) as well. So, when constructing the Dropbox object, make sure you supply the clientId, and if needed clientSecret.

from dropbox-sdk-js.

Lioness100 avatar Lioness100 commented on June 10, 2024

Thanks!

from dropbox-sdk-js.

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.