Error validating client secret

Should middleware not redirect, per your "Good Middleware" example? Most likely some of your code is setting headers in the first tick and then you are running an async callback in a future tick.You know I have this exact problem due to what you call a problematic middleware, however I need a case where I return response but would like to do further processing in a separate controller as part of the chain, how do I go about suppressing this error? In between, the response header gets sent, but then further headers (like a 30X redirect) try to add extra headers, but it's too late since the response header has already been transmitted.I'm not sure exactly what's causing your error, but look at any callbacks as potential areas to investigate. Get rid of app.configure() and just call directly in your top level scope.

error validating client secret-7

When you do response.redirect(...) in node, a 30X redirect header will be sent in the response.

I boiled my head over this issue and it has happened due to a careless mistake on handling the callbacks.

non returned callbacks cause the response to be set twice.!

Facebook({ app Id : fb Id, app Secret: fb Secret, callback: fb Callback Address, scope: 'offline_access,email,user_about_me,user_activities,manage_pages,publish_stream', failed Uri: '/noauth' }) ])); app.use(app.router); }); app.get('/auth/facebook', function(req, res) { req.authenticate("facebook", function(error, authenticated) { if (authenticated) { res.redirect("/great"); console.log("ok cool."); console.log(res['req']['session']); } }); }); app.get('/noauth', function(req, res) { console.log('Authentication Failed'); res.send('Authentication Failed'); }); app.get('/great', function( req, res) { res.send('Supercoolstuff'); }); app.listen(8888); .

(http.js:5) at Server Header (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/patch.js:) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at param (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/middleware/router.js:1) at pass (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/middleware/router.js:1) at Object.router [as handle] (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/middleware/router.js:197:6) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at [as handle] (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/index.js:153:7) Error: Can't set headers after they are sent. (http.js:5) at Server Header (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/patch.js:) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:207:9) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at param (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/middleware/router.js:1) at pass (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/middleware/router.js:1) at Object.router [as handle] (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/middleware/router.js:197:6) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at [as handle] (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/index.js:153:7) Error: Can't set headers after they are sent. (http.js:5) at Server Header (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/patch.js:) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:207:9) at [as handle] (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/index.js:153:7) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at HTTPServer.handle (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:211:3) at Object.handle (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) Error: Can't set headers after they are sent. (http.js:5) at Server Header (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/patch.js:) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:207:9) at HTTPServer.handle (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:211:3) at Object.handle (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at /home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/middleware/session.js:323:9 at /home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/middleware/session.js:338:9 node.js:134 throw e; // Tick error, or 'error' event on first tick ^ Error: Can't set headers after they are sent. (http.js:5) at Server Header (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/patch.js:) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:1) at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/http.js:207:9) at /home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/middleware/session.js:323:9 at /home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/middleware/session.js:338:9 at fb Id= "XXX"; var fb Secret= "XXXXXX"; var fb Callback Address= " var cookie Secret = "node"; // enter a random hash for security var express= require('express'); var auth = require('connect-auth') var app = express.create Server(); app.configure(function(){ app.use(Parser()); app.use(express.method Override()); app.use(express.cookie Parser()); app.use(express.session({secret: cookie Secret})); app.use(auth([ auth.

I than received the following error: (http.js:5) at Server Response._render Headers (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect/lib/patch.js:) at Server Response.write Head (http.js:8) at /home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/auth.strategies/facebook.js: at /home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/index.js:1 at next (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/strategy Executor.js:) at [object Object](/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/auth Execution Scope.js:32:3) at [object Object](/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/auth Execution Scope.js:29:8) at [object Object].redirect (/home/eugene/public_html/all_things_node/projects/fb2/node_modules/connect-auth/lib/auth Execution Scope.js:16:8) at [object Object].

The error "Error: Can't set headers after they are sent." means that you're already in the Body or Finished state, but some function tried to set a header or status Code.

When you see this error, try to look for anything that tries to send a header after some of the body has already been written.

For example, look for callbacks that are accidentally called twice, or any error that happens after the body is sent. I think (hope) I've wrapped my head around it, wanted to write it here for reference.

In your case, you called also watch out for this classic mistake: res.redirect() doesn't stop statement execution... Otherwise other code could be executed which could unintentiallly cause the famous header error. When you add middleware to connect or express (which is built on connect) using the // middleware that does not modify the response body var does Not Modify Body = function(request, response, next) { request.params = { a: "b" }; // calls next because it hasn't modified the header next(); }; // middleware that modify the response body var does Modify Body = function(request, response, next) { Header("Content-Type", "text/html"); response.write("+1 This is a great explanation, but what about the case when you use res.redirect()?

I frequently run into this problem when the middleware is trying to redirect based on some condition.