You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

belt_basya's avatar
belt_basya
Explorer | Level 3
7 months ago

Trouble Obtaining Refresh Token Alongside Access Token from Dropbox OAuth2 in Local Environment

I'm trying to integrate Dropbox into my web application using OAuth2. My code seems to be working correctly, but I'm only receiving the access token and not the refresh token upon successful login. I'm developing in a local environment and using ngrok for a callback URL.

Code Snippets:

- Front-end code (relevant part):


const handleConnect = (service) => {
    const connectionUrl = `${process.env.REACT_APP_HOST_URL}/auth/${service}`;
    const authWindow = window.open(connectionUrl, "_blank");
    window.addEventListener('message', event => {
      if (event.data.message === 'Success') {
        sendTokensToServer({ ...event.data, path: connectedServices[service].path });
          authWindow.close();
      }
    });
};

- Back-end code (relevant part):


const DropboxOAuth2Strategy = require('passport-dropbox-oauth2').Strategy;

passport.use(
    new DropboxOAuth2Strategy(
        {
            apiVersion: "2",
            callbackURL: `${process.env.CALLBACK_URL}/oauth/dropbox/callback`,
            clientID: process.env.DROPBOX_CLIENT_ID,
            clientSecret: process.env.DROPBOX_CLIENT_SECRET,
            // Missing option?
        },
        (accessToken, refreshToken, profile, cb) => {
            console.log(accessToken, refreshToken)
            cb(null, profile);
        }
    )
);

router.get("/auth/dropbox", passport.authenticate("dropbox-oauth2"));

router.get("/oauth/dropbox/callback",
    passport.authenticate("dropbox-oauth2", { failureRedirect: "/" }),
    (req, res) => {
        res.redirect("/success?service=Dropbox");
    }
);


- Question:

* Is using ngrok as a callback URL in my local environment preventing me from receiving the refresh token?
* If not, what could be causing the missing refresh token?
* Are there any additional configuration options needed for the `DropboxOAuth2Strategy` to obtain the refresh token?

- Additional Information:

* I've checked the Dropbox API documentation for OAuth2 and ensured my code is following the steps correctly.

Thanks in advance for any help!

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,885 PostsLatest Activity: 16 hours ago
326 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!