1

I am sending request to dropbox to get request_token. Once I get the request_token back, i need to redirect to "authorize_url": "https://www.dropbox.com/1/oauth/authorize?oauth_token=H4bYgmttvjA1S332Zv" to get access_token.

in javascript I know we can use window.location to redirect the url.but in node.js how do i do it?

exports.dropboxRequestToken = function(req, res){

    var app = dbox.app({ 
        "app_key": secrets.dropbox.key,
        "app_secret": secrets.dropbox.secret,
        "root": secrets.dropbox.root 
    });

    app.requesttoken(function(status, request_token){

        //console.log("status: " + status);

        if(status == 200){
            req.session.dropbox = {

                request_token: request_token,
                app_info: {
                    app_key: req.param('app_key'),
                    app_secret: req.param('app_secret'),
                    root: req.param('root')
                }
            };

            //I need to reidrect user to this URL https://www.dropbox.com/1/oauth/authorize?oauth_token=H4bYgmttvjA1S332Zv

        }
    });

};

here's the output of request token:

{
  "status": 200,
  "request_token": {
    "oauth_token_secret": "ICOyjb0SqG69834ixo",
    "oauth_token": "H4bYgmttvjA1S332Zv",
    "authorize_url": "https://www.dropbox.com/1/oauth/authorize?oauth_token=H4bYgmttvjA1S332Zv"
  }
}
qinking126
  • 11,385
  • 25
  • 74
  • 124
  • Already answered. Check http://stackoverflow.com/questions/11355366/nodejs-redirect-url – Rami Feb 24 '14 at 01:04

1 Answers1

1

Use res.redirect! In this case I think that would be:

res.redirect(request_token.authorize_url);

Be sure not to forget that if the user doesn't have successful authentication, the response should also be sent. Maybe you will want to serve them an error code 500 and some further information. Also keep in mind that you may want to serve them such an error page if the request cannot be sent because Dropbox is down.

Spork
  • 1,631
  • 1
  • 21
  • 37