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

HELP WANTED: Authentication strategy 'jwt' is not registered. #668

Closed
jonnyparris opened this Issue Apr 18, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@jonnyparris
Copy link

jonnyparris commented Apr 18, 2018

Steps to reproduce

My authentication service definition below throws an error "Authentication strategy 'jwt' is not registered." when the app receives a request to the authentication endpoint.
I tried logging the app strategies in the code below too but they only return Session; no JWT or Local strategies.

Does this look right? Should I be looking for problems elsewhere in the codebase that could override what's here somehow?

const authentication = require('@feathersjs/authentication')
const jwt = require('@feathersjs/authentication-jwt');
const local = require('@feathersjs/authentication-local');

module.exports = function(app) {
  const config = app.get('authentication')

    // Set up authentication with the secret
  app.configure(authentication(config));
  app.configure(jwt());
  app.configure(local());

  // Is there a way to verify/log what strategies have been configured at this point?

  app.service('authentication').hooks({
    before: {
      create: [
        authentication.hooks.authenticate(config.strategies) // ==> ['jwt', 'local']
      ],
      remove: [
        authentication.hooks.authenticate('jwt')
      ]
    }
  })
}

Any help much appreciated!

Expected behavior

'/authentication' endpoint should return a jwt.

Actual behavior

error: (400) Route: /authentication - Authentication strategy 'jwt' is not registered.
main_1    | info: BadRequest: Authentication strategy 'jwt' is not registered.
main_1    |     at new BadRequest (/usr/src/app/node_modules/@feathersjs/errors/lib/index.js:86:17)
main_1    |     at Object.<anonymous> (/usr/src/app/node_modules/@feathersjs/authentication/lib/hooks/authenticate.js:44:29)
main_1    |     at promise.then.hookObject (/usr/src/app/node_modules/@feathersjs/commons/lib/hooks.js:174:73)
main_1    |     at <anonymous>
main_1    |     at process._tickCallback (internal/process/next_tick.js:118:7)

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working):

"@feathersjs/authentication": "^2.1.3",
"@feathersjs/authentication-client": "^1.0.2",
"@feathersjs/authentication-jwt": "^2.0.0",
"@feathersjs/authentication-local": "^1.1.2",
"@feathersjs/client": "^3.4.4",
"@feathersjs/configuration": "^1.0.2",
"@feathersjs/errors": "^3.3.0",
"@feathersjs/express": "^1.2.1",
"@feathersjs/feathers": "^3.1.4",
"@feathersjs/socketio": "^3.2.1",

NodeJS version:
8.7.0

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Apr 18, 2018

Can you confirm that config.strategies is // ==> ['jwt', 'local']? It come from https://github.com/feathersjs/feathers-chat/blob/master/config/default.json#L12.

@jonnyparris

This comment has been minimized.

Copy link
Author

jonnyparris commented Apr 18, 2018

yup, confirmed

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Apr 19, 2018

What is the payload of your authentication request? Anything else in the setup that's different than the feathers-chat?

@jonnyparris

This comment has been minimized.

Copy link
Author

jonnyparris commented Apr 20, 2018

Thanks for your help and replying so quickly @daffl - using that chat app to verify that the api was fine led me to this issue where I realised that the app wasn't being mounted properly because it's a subapp.

Using subApp.setup(mainApp) after the mainApp starts as described in the Express section of the docs fixed this issue for me. Hopefully this can help any future googlers too.

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.