cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Whether you want to work on being more organized, your productivity or you want to use AI to make your life easier, we’ve got something for you right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

/oauth2/token route is returning a binary in response

/oauth2/token route is returning a binary in response

us0p
Explorer | Level 3

Hi, i'm having problems when deploying my integration to my QA environment, i have already tested it in development and everything was right but i'm getting a totally different response in the route /oauth2/token then what i was receiving during my tests.
The app environments are the same and the code too, so i'm lost over here, any answer could come handy!

Here is how i start my OAUTH flow:
The client will call this route witch should redirect the client to Dropbox authorization page:

 

    async get(req, res) {
        const usuario = await Usuario.findByPk(req.params.usuario_id);

        return res.redirect(
            `https://www.dropbox.com/oauth2/authorize?client_id=${process.env['APP_KEY']}&response_type=code&redirect_uri=${process.env.DROPBOX_WEBHOOK_URL}&token_access_type=offline&state=unidade_id:${usuario.unidade_id}`
        );
    }

 

After the user authorizing my app the code bellow is called witch is the code for the route provided in the redirect_uri query param:

 

    async index(req, res) {
        const params = new URLSearchParams();
        params.append('code', req.query.code);
        params.append('client_id', process.env['APP_KEY']);
        params.append('client_secret', process.env['APP_SECRET']);
        params.append('grant_type', 'authorization_code');

        params.append('redirect_uri', process.env.DROPBOX_WEBHOOK_URL);

        const fronURLRedirect = new URL(
            '/dropbox',
            process.env['APP_FRONT_URL']
        );
        try {
            const { data } = await axios.post(
                process.env['DROPBOX_OAUTH2_TOKEN_ROUTE'],
                params
            );

            const [_, unidade_id] = req.query.state.split(':');

            await AcessoDropbox.create({
                ...data,
                update_token_date: new Date(),
                unidade_id,
            });

            fronURLRedirect.pathname = '/dropbox/sucesso';
            return res.redirect(fronURLRedirect.href);
        } catch (error) {
            console.log(error);

            fronURLRedirect.pathname = '/dropbox/erro';
            return res.redirect(fronURLRedirect.href);
        }
    }

 

And after that our app is successfully authorized, at least during development, here is the return value that i receive from my POST call in the code above in development:

us0p_0-1695329213423.png

And here is an example of what i receive back in QA with the same code, same app key and secret, the only difference is the redirect_uri:

us0p_2-1695329318871.png
Here is a full print of my debugging:

us0p_5-1695329485595.png

I'm also receiving the query params as it should:

us0p_3-1695329405356.png

It looks like i'm receiving a binary as a response witch is totally different from what i was receiving during my tests, i searched the docs and did some googling but no luck!

My Dropbox app isn't applied to production, i'm wondering if that's the problem.

3 Replies 3

Greg-DB
Dropbox Staff

Thanks for the detailed post!

 

The 'development' versus 'production' status of your app affects how many accounts can be connected to your app but it doesn't affect the content types/encodings of the messages returned by the API.

 

Does your development environment have a different version or configuration of 'axios' than your QA environment? It looks like network client in the QA environment may be encoding/decoding the response differently. For instance, it seems like your client may be requesting a content-encoding like gzip, but then not decompressing the response with the gzip content-encoding and instead just showing you the compressed content.

 

Can you print the headers for both the request and response? That may be useful in debugging this. Be sure to redact any secret values though.

us0p
Explorer | Level 3

Hey Greg, thanks for your reply and sorry the dalay!

I did as you suggested and printed the headers for both environments and they were pretty much the same, the only difference were in the request headers:

 

// Request Headers Development
 AxiosHeaders {
  Accept: 'application/json, text/plain, */*',
  'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
  'Accept-Encoding': 'gzip, compress, deflate, br',
  'User-Agent': 'axios/1.3.3',
  'Content-Length': '240'
}

// Request Headers QA
 AxiosHeaders {
  Accept: 'application/json, text/plain, */*',
  'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
  'User-Agent': 'axios/1.2.0',
  'Content-Length': '199',
  'Accept-Encoding': 'gzip, deflate, br'
}

 

 

 

// Response Headers - Dev 
AxiosHeaders {
  'cache-control': 'no-cache, no-store, must-revalidate',
  expires: '0',
  pragma: 'no-cache',
  'x-content-type-options': 'nosniff',
  'x-frame-options': 'SAMEORIGIN',
  'x-server-response-time': '216',
  'content-type': 'application/json',
  'accept-encoding': 'identity,gzip',
  date: 'Mon, 25 Sep 2023 18:50:34 GMT',
  server: 'envoy',
  vary: 'Accept-Encoding',
  'x-dropbox-response-origin': 'far_remote',
  'x-dropbox-request-id': '75143489d10744ea8ef2f4a1175eda99',
  connection: 'close',
  'transfer-encoding': 'chunked'
} 

// Response Headers - QA
 AxiosHeaders {
  'cache-control': 'no-cache, no-store, must-revalidate',
  expires: '0',
  pragma: 'no-cache',
  'x-content-type-options': 'nosniff',
  'x-frame-options': 'SAMEORIGIN',
  'x-server-response-time': '510',
  'content-type': 'application/json',
  'accept-encoding': 'identity,gzip',
  date: 'Mon, 25 Sep 2023 14:49:36 GMT',
  server: 'envoy',
  vary: 'Accept-Encoding',
  'x-dropbox-response-origin': 'far_remote',
  'x-dropbox-request-id': '9e5db6680a4542648248855fc72ff50d',
  connection: 'close',
  'transfer-encoding': 'chunked'
} 

 

So as you can see the difference is only in the Request Headers, in the Accept-Encoding and User-Agent headers, altough the version of Axios in both environments is the same, the user agent is different.
I added a Accept-Encoding header like the one i'm using in Dev, but still the same

Greg-DB
Dropbox Staff

Can you clarify what you mean when you say "altough the version of Axios in both environments is the same, the user agent is different"? The "user-agent" request header value being set by the client does seem to indicate that a different version number of Axios is being used in each case.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    us0p Explorer | Level 3
What do Dropbox user levels mean?