0

I am working on a Spring-MVC application and I would like to integrate Dropbox functionality into it. As I read the examples, I saw that there is some code which I can use. But this involves the user copy pasting the access token, which is not applicable in real world applications, plus I cannot find a way to set the redirect URL when authentication is complete. What changes should I make so the code does not need to copy pasted, but can be retrieved directly.

Code :

 public void connectToDropbox() {

        DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);

        DbxRequestConfig config = new DbxRequestConfig("JavaTutorial/1.0",
                Locale.getDefault().toString());

        DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);


        // Have the user sign in and authorize your app.
        String authorizeUrl = webAuth.start();
        System.out.println("1. Go to: " + authorizeUrl);
        System.out.println("2. Click \"Allow\" (you might have to log in first)");
// No, I dont want to copy the authorization code. 
        System.out.println("3. Copy the authorization code.");
        String code = null;
        try {
            code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();
        } catch (IOException e) {
            e.printStackTrace();
        }

Controller code :

 @RequestMapping(value = "/logindropbox")
    public String loginIntoDropbox(){
        ConnectDropbox connectDropbox = new ConnectDropbox();
        connectDropbox.connectToDropbox();
        return "rediect:/dashboard";
    }

There was only one answer I could find on SO, but that was of no use. Any help would be nice. Thanks a lot. :-)

1
  • you have found the solution? I have the same problem, thanks Commented Apr 18, 2020 at 8:32

1 Answer 1

2

[Cross-linking for reference: https://www.dropboxforum.com/hc/communities/public/questions/203308909-Dropbox-authentication-without-copy-pasting-the-access-token-manually-in-Java- ]

The Dropbox Java Core SDK tutorial does use the flow where the user copies and pastes the authorization code manually. This is done using the provided DbxWebAuthNoRedirect class.

For apps where a redirect URI can be used to deliver the authorization code automatically, you'll want to use the DbxWebAuth class instead. The documentation has some sample code:

https://dropbox.github.io/dropbox-sdk-java/api-docs/v1.7.x/com/dropbox/core/DbxWebAuth.html

There's also a "web-file-browser" sample app included with the SDK download that uses DbxWebAuth.

1
  • I will accept this answer, as it gives me what I requires, but I have already programmed it with REST authentication, so I don't need the data anymore, maybe other users who have this problem will be able to use it. I will later try the information when I get time. Commented Jul 10, 2015 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.