Reputation: 769
I am new to node.js, so bear with me here. I am trying to make a POST request after a GET. Idea is once user hits the homepage, I want to redirect that user to salesforce and do an OAUth dance. I am using expressJS and mikeal's request. This is the code I have so far
server.get('/', function(req, res){
var client_id = "xxx";
var client_secret = "xxx";
var redirect_uri = "https://192.168.233.105:8000/callback";
var grant_type = "authorization_code";
var remotereq = request.post('https://na1.salesforce.com/services/oauth2/token').form(
{"client_id":client_id,
"client_secret":client_secret,
"redirect_uri":redirect_uri,
"grant_type":grant_type,
"immediate":'true'
}
);
//How do I get the expressJS res object to use the remotereq object?
});
When I hit the home page, the request just hangs. I am thinking I have to somehow get the expressJS response object to play nice with the mikeal/request object. How do I connect the two together?
Upvotes: 1
Views: 446
Reputation: 203231
You can pipe the result of request.post
directly to res
:
remotereq.pipe(res);
That would send the result to the client verbatim, including all original headers.
Upvotes: 3