passport-http-bearer icon indicating copy to clipboard operation
passport-http-bearer copied to clipboard

Not Return Status Code 401 for API access without token

Open twhtanghk opened this issue 12 years ago • 2 comments
trafficstars

Try to access api without defining the token. The server reports property 'statusCode' assigned with 'undefined' value at 150 of passport authenticate.js. Any suggestion to fix the statement res.statusCode = rstatus || 401; if rstatus is undefined.

TypeError: Cannot set property 'statusCode' of undefined at allFailed (/home/whtang/workspace/uc/node_modules/passport/lib/passport/middleware/authenticate.js:150:22) at attempt (/home/whtang/workspace/uc/node_modules/passport/lib/passport/middleware/authenticate.js:231:28) at Context.module.exports.delegate.fail (/home/whtang/workspace/uc/node_modules/passport/lib/passport/middleware/authenticate.js:226:9) at Context.actions.fail (/home/whtang/workspace/uc/node_modules/passport/lib/passport/context/http/actions.js:35:22) at Strategy.authenticate (/home/whtang/workspace/uc/node_modules/passport-http-bearer/lib/strategy.js:113:29) at attempt (/home/whtang/workspace/uc/node_modules/passport/lib/passport/middleware/authenticate.js:243:16) at Passport.authenticate (/home/whtang/workspace/uc/node_modules/passport/lib/passport/middleware/authenticate.js:244:7) at zappa.app.route (/home/whtang/workspace/uc/node_modules/zappa/lib/zappa.js:490:34) at callbacks (/home/whtang/workspace/uc/node_modules/zappa/node_modules/express/lib/router/index.js:272:11) at param (/home/whtang/workspace/uc/node_modules/zappa/node_modules/express/lib/router/index.js:246:11) at pass (/home/whtang/workspace/uc/node_modules/zappa/node_modules/express/lib/router/index.js:253:5) at Router._dispatch (/home/whtang/workspace/uc/node_modules/zappa/node_modules/express/lib/router/index.js:280:5) at Object.middleware as handle at next (/home/whtang/workspace/uc/node_modules/zappa/node_modules/express/node_modules/connect/lib/http.js:204:15) at Passport.initialize (/home/whtang/workspace/uc/node_modules/passport/lib/passport/middleware/initialize.js:69:5) at next (/home/whtang/workspace/uc/node_modules/zappa/node_modules/express/node_modules/connect/lib/http.js:204:15) at resume (/home/whtang/workspace/uc/node_modules/express/node_modules/connect/lib/middleware/static.js:60:7) at SendStream.error (/home/whtang/workspace/uc/node_modules/express/node_modules/connect/lib/middleware/static.js:73:37) at SendStream.EventEmitter.emit (events.js:95:17) at SendStream.error (/home/whtang/workspace/uc/node_modules/express/node_modules/send/lib/send.js:147:51) at SendStream.onStatError (/home/whtang/workspace/uc/node_modules/express/node_modules/send/lib/send.js:248:48) at SendStream.pipe (/home/whtang/workspace/uc/node_modules/express/node_modules/send/lib/send.js:320:26) at Object.oncomplete (fs.js:107:15)

Thanks, Tommy Tang

twhtanghk avatar Sep 18 '13 06:09 twhtanghk

Problem fixed by fall back from Zappajs to Coffee Script. It seems that Zappajs not properly passed response to middleware so that the undefined "res" is referenced in statement res.statusCode = rstatus || 401.

Thanks, Tommy Tang

twhtanghk avatar Sep 18 '13 08:09 twhtanghk

Maybe close this issue if it's fixed?

peteruithoven avatar Dec 20 '16 14:12 peteruithoven