我正在使用node.js请求模块从API获取id_token.在获取id_token之后,我想向重定向的url发送带有set-cookie标头的重定向uri响应.但我无法弄明白该怎么做.
这是我的代码:
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'} //Query string data var options = { method: 'POST',//Specify the method body: postData,url: 'http://localhost:4000/server/token',json: true,headers: headers } request(options,function(error,response,body){ if(error) { console.log(error); } else { //send a redirect uri and set-cookie header response } });
我试过用
res.redirect(302,"http://localhost:9000");
它能够重定向,但我也无法发送cookie
任何帮助表示赞赏.