I am using node.js module requestto retrieve id_token from API. After receiving this id_token, I want to send a response redirect uriusing set-cookie header to the redirected url. But I canβt figure out how to do this.
Here is my code:
app.use("/nodejs-server/retrieveCode", function(req, res) {
var clientID = 'some random string'
var client_Secret = 'another random string'
var code_token = clientID + ":" + client_Secret
var buffer = new Buffer(code_token)
var token = buffer.toString('base64')
var rtoken = "Basic " + token;
var headers = {
'Content-Type': 'application/json',
'Authorization': rtoken
}
var postData = {grant_type: 'authorization_code', code: req.query.code, redirect_uri: 'http://localhost:3000/nodejs-server/retrieveCode'}
var options = {
method: 'POST',
body: postData,
url: 'http://localhost:4000/server/token',
json: true,
headers: headers
}
request(options
, function(error, response, body){
if(error) {
console.log(error);
} else {
}
});
I tried to use
res.redirect(302, "http://localhost:9000");
and it can redirect, but I also canβt send a cookie with it.
Any help is appreciated.
source
share