We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

us0p's avatar
us0p
Explorer | Level 3
2 years ago

/oauth2/token route is returning a binary in response

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:

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:


Here is a full print of my debugging:

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

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.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox 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's avatar
      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's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox 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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,877 PostsLatest Activity: 12 months ago
325 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!