jaredhanson / passport-http-bearer

HTTP Bearer authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-http-bearer/?utm_source=github&utm_medium=referral&utm_campaign=passport-http-bearer&utm_content=about
MIT License
951 stars 142 forks source link

Bearer : when invalid token, done(null,false) returns an error #65

Open flahol opened 2 years ago

flahol commented 2 years ago

Using passport-http-bearer, the done function with false as a user throws an error.
Same error if using passport-jwt

passport.use(
  new BearerStartegy(function (token, done) {
    return done(null, false, { message: "debug" });
  })
);

Expected behavior

From passport documentation :
By default, if authentication fails, Passport will respond with a 401 Unauthorized status, and any additional route handlers will not be invoked. If authentication succeeds, the next handler will be invoked and the req.user property will be set to the authenticated user.

Actual behavior

TypeError: Cannot convert undefined or null to object
GET http://localhost:8080/api/...

Environment

jaredhanson commented 2 years ago

Can you provide a stack trace for that error? It will help diagnose where the actual issue is.

flahol commented 2 years ago

I don't know how I can get the stack trace I have no error on the console

jaredhanson commented 2 years ago

If you set the NODE_ENV environment variable todevelopment (NODE_ENV=development), that should print out the stack trace.

flahol commented 2 years ago

I set NODE_ENV=development but it does not return anything in the console:

> obizoo-back@1.0.0 dev /home/patrice/Websites/obizoo/obizoo-back
> export NODE_ENV=development && nodemon --trace-deprecation --experimental-specifier-resolution=node server.js

[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node --trace-deprecation --experimental-specifier-resolution=node server.js`
development
Server obizoo api is running on port 8080.
jaredhanson commented 2 years ago

Unfortunately, without a stack trace its going to be hard to reproduce this issue or pinpoint it to a bug in Passport. Please update this issue with that information once you have it. Thanks.