Skip to content
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.

Server crashes when authenticating with Socket.io transport and no user entity service exists #526

Closed
compwright opened this issue Jun 17, 2017 · 4 comments

Comments

@compwright
Copy link

compwright commented Jun 17, 2017

Steps to reproduce

  1. Create a FeathersJS app which authenticates as follows:
    • Authenticate with feathers-authentication-jwt
    • Do NOT provide a users service, and leave authentication.service and authentication.path blank in the config file
    • Pass feathers-authentication-jwt a custom verifier that does not rely on any users service
  2. Create a FeathersJS client which authenticates as follows:
    • Authenticate with feathers-authentication-client
    • Use the feathers-socketio client transport
  3. Attempt to authenticate from the browser client with the jwt strategy

Expected behavior

A connection should be established and authenticated

Actual behavior

The server crashes with the following error:

  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/storage::find' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/storage::get' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/storage::create' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/storage::update' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/storage::patch' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/storage::remove' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/authentication::create' +1ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/authentication::remove' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/config::find' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/events::find' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/events::get' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/events::create' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/events::update' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/events::patch' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/events::remove' +0ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/availability::find' +1ms
  feathers-socket-commons:methods Setting up socket listener for event '58e2a3047463f61e5de6dbd6/api/availability::create' +0ms
/Users/jhill/Development/livescheduler/node_modules/feathers-authentication/lib/socket/handler.js:193
      entityService.on('updated', _updateEntity2.default);
                   ^

TypeError: Cannot read property 'on' of undefined
    at Namespace.<anonymous> (/Users/jhill/Development/livescheduler/node_modules/feathers-authentication/lib/socket/handler.js:193:20)
    at emitOne (events.js:101:20)
    at Namespace.emit (events.js:191:7)
    at Namespace.emit (/Users/jhill/Development/livescheduler/node_modules/socket.io/lib/namespace.js:212:10)
    at /Users/jhill/Development/livescheduler/node_modules/socket.io/lib/namespace.js:180:14
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)

System configuration

Module versions:

  • feathers v2.1.3
  • feathers-authentication v1.2.4
  • feathers-authentication-client v0.3.2
  • feathers-authentication-hooks v0.1.4
  • feathers-authentication-jwt v0.3.1
  • feathers-hooks v2.0.1
  • feathers-socketio v2.0.0
  • socket.io-client v2.0.3

NodeJS version: v7.9.0

Operating System: Mac OS X

Browser Version: Chrome v58.0.3029.110 (64-bit)

Module Loader: Webpack v2.2.1

@compwright compwright changed the title Server crashes when authenticating with Socket.io transport and no authentication service is defined Server crashes when authenticating with Socket.io transport and no user entity service exists Jun 17, 2017
@compwright
Copy link
Author

It appears this can be fixed by checking to see if authSettings.service is defined in socket/handler.js:24, and skipping the event bindings if it is not defined in socket/handler.js:155.

compwright added a commit to compwright/feathers-authentication that referenced this issue Jun 18, 2017
@rolandvar
Copy link
Contributor

I think I have a similar problem issue

TypeError: Cannot read property 'entity' of undefined at service.create.then.tokens (@feathersjs\authentication\lib\socket\handler.js:95:31)

It looks like the entity is not configured in strategyOptions, this is my configuration file, where is it wrong? Or did I find a bug?

"authentication": {
    "secret": "....",
    "strategies": [
      "jwt",
      "users",
      "operators"
    ],
    "path": "/authentication",
    "jwt": {
      "header": {
        "typ": "access"
      },
      "audience": "https://yourdomain.com",
      "subject": "anonymous",
      "issuer": "feathers",
      "algorithm": "HS256",
      "expiresIn": "1d"
    },
    "entity": "user",
    "service": "users",
    "users": {
      "entity": "user",
      "service": "users",
      "usernameField": "phone",
      "passwordField": "device",
      "session": false
     },
    "operators": {
      "entity": "operator",
      "service": "operators",
      "usernameField": "email",
      "passwordField": "password",
      "session": false
     }
  }

Through http everything works perfectly, this only happens with sockets.

@Zalasanjay
Copy link

i was also facing that issue and i have solved by applying this code i got solution.
so i request you to merge this code in master so that we can use it by default.

@daffl
Copy link
Member

daffl commented May 8, 2019

Feathers v4 authentication supports not using an entity service at all.

Please see the migration guide for more information. Closing this issue in order to archive this repository. Related issues can be opened at the new code location in the Feathers main repository.

@daffl daffl closed this as completed May 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants