Forum Discussion

tritnguyen's avatar
tritnguyen
Explorer | Level 3
3 years ago

How to create refresh token automatically?

Hi All,

 

I am using the refresh token for my web application and it works fine. However, the process of generating a refresh token offline that the user has to run the java app is not user friendly; the user has to run the app, clicks the output link, and then hits an Allow button; after that the user needs to copy the Authorization Code back to the program and enter is too much work. In addition, the users mostly are not developers so they do not have Java SDK or Maven to run the Java program. Is there anyway that I can provide the App key and the Secret Key and then generate the Refresh Key automatically?  The following code is the one that I use to create a refresh key.

 

DbxAppInfo appInfo;

appInfo = DbxAppInfo.Reader.readFromFile(argAppInfoFile);
DbxAuthFinish authFinish = null;
authFinish = new PkceAuthorize().authorize(appInfo);

DbxCredential credential = new DbxCredential(authFinish.getAccessToken(),
authFinish.getExpiresAt(),
authFinish.getRefreshToken(),
appInfo.getKey(),
appInfo.getSecret());
File output = new File(argAuthFileOutput);
try {
DbxCredential.Writer.writeToFile(credential, output);

}
catch (IOException ex) {
return;
}

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    No, it is not possible to fully automate the process of getting a refresh token. The user must authorize the app using the OAuth app authorization flow built into your app in order for the app to receive the resulting access token and optional refresh token. This needs to be done manually by the user at least once per Dropbox account.

     

    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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,945 PostsLatest Activity: 2 hours ago
351 Following

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

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!