Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
flahol opened this issue Dec 15, 2021 · 5 comments
Open

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

flahol opened this issue Dec 15, 2021 · 5 comments

Comments

@flahol
Copy link

flahol commented Dec 15, 2021

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

  • Operating System: ubuntu 21.10
  • Node version: 17.0.1
  bcryptjs: 2.4.3
  body-parser: 1.19.1
  connect-flash: 0.1.1
  cors: 2.8.5
  dotenv: 10.0.0
  ejs: 3.1.6
  express: 4.17.1
  express-oauth-jwt: 1.1.0
  express-session: 1.17.2
  jsonwebtoken: 8.5.1
  mariadb: 2.5.5
  passport: 0.5.0
  passport-http-bearer: 1.0.1
  passport-jwt: 4.0.0
  passport-local: 1.0.0
@jaredhanson
Copy link
Owner

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

@flahol
Copy link
Author

flahol commented Dec 15, 2021

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

@jaredhanson
Copy link
Owner

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

@flahol
Copy link
Author

flahol commented Dec 15, 2021

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

> [email protected] 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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants