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
DropboxOAuth2Strategyto 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!
token_access_type=offlineon /oauth2/authorize. You may need to refer to the documentation for your OAuth library to check if/how it supports setting that parameter.