Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
Lorenz096
4 years agoExplorer | Level 3
how can I generate a resfresh token automatically, java web app
Good Morning everyone,
I have a question about my java web app and automatic refresh token generation:
I have my access token and appName stored in application.properties file.
After that, I have a configuration class that contains getter and setter of my properties.
Finally I hava a customized java class with different dropbox methods like login, update file, delete file, etc.
After 30th September I can't have a long life access token, but I need to generate x times a refresh token and I don't know how to get it automatically and my question is:
Is there a method for generating the refresh token automatically?
right away some code examples:
APPLICATION.PROPERTIES:
application.dropbox.api.appName= myAppName
application.dropbox.api.accessToken= xxxxx
CONFIGURATION.JAVA:
@Value("${application.dropbox.api.appName}")
private String dropboxAppName;
@Value("${application.dropbox.api.accessToken}")
private String dropboxAccessToken;
DROPBOXUTILS.JAVA:
public static DbxClientV2 getV2Client(SuiteConfiguration suiteConfiguration) {
DbxRequestConfig config = DbxRequestConfig.newBuilder("").withAutoRetryEnabled().withUserLocaleFromPreferences().build();
DbxClientV2 client = new DbxClientV2(config, suiteConfiguration.getDropboxAccessToken());
return client;
}
3 Replies
- Greg-DB4 years ago
Dropbox Community Moderator
Dropbox is in the process of switching to only 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.
It is not possible to fully automate the OAuth process where the user chooses to authorize the app and the app then receives the resulting access token and optional refresh token. This needs to be done manually by the user at least once. If your app needs to maintain long-term access without the user manually re-authorizing it repeatedly, the app should request "offline" access so that it gets a refresh token. The refresh token doesn't expire and can be stored and used repeatedly to get new short-lived access tokens whenever needed, without the user manually reauthorizing the app.
For reference, while the creation of new long-lived access tokens is now deprecated, we don't currently have a plan to disable existing long-lived access tokens. (If that changes, we will of course announce that ahead of time.) That being the case, you can continue using existing long-lived access token(s) without interruption, if you have any. Also, note though that after the change you won't be able to create new long-lived access tokens.
While the change began on September 30th 2021, we're releasing it gradually, so you may not have seen your app(s) affected until now. Once it applies to your app, it would apply regardless of the "Access token expiration" setting for your app, and that setting may no longer be available for your app.
Here's some example code of processing the authorization flow using the official Dropbox API v2 Java SDK, such as to get a refresh token: https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/authorize/src/main/java/com/dropbox/core/examples/authorize
For instance, here's a line where it requests "offline" access in order to get a refresh token: https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/authorize/src/main/java/com/dropbox/core/examples/authorize/ScopeAuthorize.java#L39
And here's an example of storing the refresh token: https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/authorize/src/main/java/com/dropbox/core/examples/authorize/Main.java#L98
As long as you supply the necessary credentials, the SDK will then handle the refresh process for you automatically, e.g.: https://github.com/dropbox/dropbox-sdk-java/blob/e52fc828c7c753e04c3fa9d47ab6de7e85d000c4/examples/account-info/src/main/java/com/dropbox/core/examples/account_info/Main.java
- Jamesbond00714 years agoExplorer | Level 3
Greg-DB wrote:Dropbox is in the process of switching to only 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.
It is not possible to fully automate the OAuth process where the user chooses to authorize the app and the app then receives the resulting access token and optional refresh token. This needs to be done manually by the user at least once. If your app needs to maintain long-term access without the user manually re-authorizing it repeatedly, the app should request "offline" access so that it gets a refresh token. The refresh token doesn't expire and can be stored and used repeatedly to get new short-lived access tokens whenever needed, without the user manually reauthorizing the app.
For reference, while the creation of new long-lived access tokens is now deprecated, we don't currently have a plan to disable existing long-lived access tokens. (If that changes, we will of course announce that ahead of time.) That being the case, you can continue using existing long-lived access token(s) without interruption, if you have any. Also, note though that after the change you won't be able to create new long-lived access tokens.
While the change began on September 30th 2021, we're releasing it gradually, so you may not have seen your app(s) affected until now. Once it applies to your app, it would apply regardless of the "Access token expiration" setting for your app, and that setting may no longer be available for your app.
Here's some example code of processing the authorization flow using the official Dropbox API v2 Java SDK, such as to get a refresh token: https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/authorize/src/main/java/com/dropbox/core/examples/authorize
For instance, here's a line where it requests "offline" access in order to get a refresh token: https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/authorize/src/main/java/com/dropbox/core/examples/authorize/ScopeAuthorize.java#L39
And here's an example of storing the refresh token: https://github.com/dropbox/dropbox-sdk-java/blob/filmorago-premium-apk/examples/authorize/src/main/java/com/dropbox/core/examples/authorize/Main.java#L98
As long as you supply the necessary credentials, the SDK will then handle the refresh process for you automatically, e.g.: https://github.com/dropbox/dropbox-sdk-java/blob/e52fc828c7c753e04c3fa9d47ab6de7e85d000c4/examples/account-info/src/main/java/com/dropbox/core/examples/account_info/Main.java
Thank you so much for explaining it in detail.
- Lorenz0964 years agoExplorer | Level 3
Thank you for supporting, I'm going to do that!
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!