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

feathers-authentication 'local' strategy requires token? #394

Closed
MidnightP opened this Issue Jan 7, 2017 · 10 comments

Comments

Projects
None yet
3 participants
@MidnightP
Copy link

MidnightP commented Jan 7, 2017

Posted this question on stackoverflow, but perhaps it's better to ask it here. As I'm pretty new with Feathers, please accept my apologies if the question is unclear or simply stems an ignorance about Node.

Steps to reproduce

I'm using the authentication-client with:

app.configure(authentication({
        strategy: 'local',
        storage: window.localStorage,
      }))

app.authenticate(
      Object.assign({}, { strategy: 'local' }, {
      email,
      password,
    }))

Then in the client I have something like this:

app.authenticate(formData)
      .then((response) => {}
I get a token in return which allows the following (copied from migration instructions here):

app.verifyToken(response.accessToken).then((payload) => { 
  app.service('users').get(payload.userId)
}

Expected behavior

Succesful authentication

Actual behavior

feathers-authentication:hooks:authenticate Attempting to authenticate using jwt,local strategy with options +36ms {}
  feathers-authentication:passport:authenticate Passport request object +0ms { query: undefined,
  body: undefined,
  params: { query: {}, provider: 'rest' },
  headers: {},
  cookies: {},
  session: {} }
  feathers-authentication:passport:authenticate Authentication strategy 'jwt' failed +2ms Error: No auth token
    at JwtStrategy.authenticate (/home/pim/projects/bijlesismore/starters/Feathers-React-Starterkit/node_modules/passport-jwt/lib/strategy.js:87:26)
    at attempt (/home/pim/projects/bijlesismore/starters/Feathers-React-Starterkit/node_modules/feathers-authentication/lib/passport/authenticate.js:128:20)
    at /home/pim/projects/bijlesismore/starters/Feathers-React-Starterkit/node_modules/feathers-authentication/lib/passport/authenticate.js:132:9
    at /home/pim/projects/bijlesismore/starters/Feathers-React-Starterkit/node_modules/feathers-authentication/lib/passport/authenticate.js:38:14
    at Object.<anonymous> (/home/pim/projects/bijlesismore/starters/Feathers-React-Starterkit/node_modules/feathers-authentication/lib/hooks/authenticate.js:57:47) undefined
  feathers-authentication:passport:authenticate Passport request object +1ms { query: undefined,
  body: undefined,
  params: { query: {}, provider: 'rest' },
  headers: {},
  cookies: {},
  session: {} }
  feathers-authentication:passport:authenticate Authentication strategy 'local' failed +0ms { message: 'Missing credentials' } 400
error: (401) Route: /users/5 - No auth token
info: NotAuthenticated: No auth token
    at NotAuthenticated.ExtendableBuiltin (/home/pim/projects/bijlesismore/starters/Feathers-React-Starterkit/node_modules/feathers-errors/lib/index.js:21:28)
    at NotAuthenticated.FeathersError (/home/pim/projects/bijlesismore/starters/Feathers-React-Starterkit/node_modules/feathers-errors/lib/index.js:96:116)
    at new NotAuthenticated (/home/pim/projects/bijlesismore/starters/Feathers-React-Starterkit/node_modules/feathers-errors/lib/index.js:149:117)
    at /home/pim/projects/bijlesismore/starters/Feathers-React-Starterkit/node_modules/feathers-authentication/lib/hooks/authenticate.js:79:31

Should I get a token in response when using local strategy? Should I send it as a param along with the .get for the user? I suppose not, what am I missing? No luck with the docs so far.

@Ivykp

This comment has been minimized.

Copy link

Ivykp commented Jan 7, 2017

@MidnightP can you show us your server authentication service configuration?

@marshallswain

This comment has been minimized.

Copy link
Member

marshallswain commented Jan 7, 2017

Also need to see the beforeCreate hook on the authentication service.

@MidnightP

This comment has been minimized.

Copy link
Author

MidnightP commented Jan 7, 2017

Im relying on these recommendations for authentication v1 :
https://github.com/feathersjs/feathers-authentication/blob/master/docs/migrating.md

I have:

app.use('/users', service(options))
    .configure(jwt())
    .configure(local())

In my config:

"auth": {
    "idField": "id",
    "secret": "...very secret",
    "local": {},
}

I'm using the proposed hooks in the user service and one hook for authentication service, seen here:

app.service('authentication').hooks({
    before: {
      create: [
        // should this hook also be used in the user service ?
        auth.hooks.authenticate(['jwt', 'local'])
      ]
    },

Is that hepful?

@marshallswain

This comment has been minimized.

Copy link
Member

marshallswain commented Jan 13, 2017

@MidnightP, sorry this fell through the cracks. Were you able to get this figured out? I can probably create a repo with a working app in it for you, if not.

@MidnightP

This comment has been minimized.

Copy link
Author

MidnightP commented Jan 14, 2017

That would be awesome!

I didn't figure this out yet. I feel I'm missing something.

My repo is here, just in case: https://github.com/MidnightP/Feathers-React-Starterkit

@MidnightP

This comment has been minimized.

Copy link
Author

MidnightP commented Jan 16, 2017

By the way, an example would also be helpful to have along with the instructions for migrating to v1.x.x

@MidnightP

This comment has been minimized.

Copy link
Author

MidnightP commented Jan 17, 2017

@marshallswain, got a chance to look at this?

@marshallswain

This comment has been minimized.

Copy link
Member

marshallswain commented Jan 17, 2017

Nope. Sorry, work on the new place is almost finished. It kinda eats all the minutes up right now. It'll probably be a couple days before I get to this. By then, we might have a generator, who knows.

@MidnightP

This comment has been minimized.

Copy link
Author

MidnightP commented Jan 17, 2017

@MidnightP

This comment has been minimized.

Copy link
Author

MidnightP commented Jan 18, 2017

I solved this in another which uses sockets. Not sure what was wrong but the above info indeed seems to be correct & complete. Closing this

@MidnightP MidnightP closed this Jan 18, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.