Skip to content

failWithError issue. #205

@haozeng

Description

@haozeng

does this work with 'basic' strategy ?
I am getting 500 for authentication when I tried to get back the error. Here is my code sample:
Without failWithError, i am getting 401 and I looked into the source code and find the
if (options.failWithError) {
console.log(http.STATUS_CODES[res.statusCode])
return next(new AuthenticationError(http.STATUS_CODES[res.statusCode], rstatus));
}
and it seems it is set up properly. Any thoughts on this ?

  authenticate: (request, response, callback) =>
    console.log('success_non')
    response.send { authentication_token: request.user.authentication_token }

  errorhandling: (error, request, response, callback) =>
    console.log('error')
    response.json(error)

  setRoutes: (key, server) ->
    super
    server.get("/authentication", passport.authenticate('basic', { session: false, failWithError: true }), @authenticate, @errorhandling)

HTTP/1.1 500 Internal Server Error
WWW-Authenticate: Basic realm="Users"
Content-Type: application/json
Content-Length: 26
Date: Wed, 19 Feb 2014 22:57:54 GMT
Connection: keep-alive

{"message":"Unauthorized"}
curl -i --user tstuser1:12345678 -H 'Content-type: application/json' -X GET http://localhost:8080/authentication

{"message":"Unauthorized"}

haozeng commented 7 minutes ago

    passport.use new BasicStrategy { passReqToCallback: true }, (request, username, password, done) =>
      # Set the master db for now and we want to load the right database from the request object
      User.findOne { username: username }, (error, user) ->
        if error
          return done(error)
        if not user
          console.log 'dsf'
          return done(null, false, { message: 'Username does not exist'} )
        if not user.validPassword(password)
          return done(null, false, { message: 'Incorrect Password'} )
        return done(null, user)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions