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

Make socket.feathers data available in authentication hooks #475

Closed
thomas-p-wilson opened this issue Apr 9, 2017 · 0 comments
Closed

Comments

@thomas-p-wilson
Copy link
Contributor

In my application I need to pass certain information about the connection/request to hooks on some of my services, including my users service.

https://github.com/feathersjs/feathers-authentication/blob/master/src/socket/handler.js#L58 forbids this by not including the socket.feathers object (if available), thus the only data available to the authentication hooks over socket/primus is that specified on the aforementioned line 58.

Given:

const app = feathers();
app
    .configure(hooks())
    .configure(rest())
    .configure(socketio((io) => {
        io.use((socket, next) => {
            console.log('Socket request');
            socket.feathers.data = 'Hello world';
            next();
        });
    }))
    .configure(authentication());

app.service('authentication').hooks({
    'before': {
        'create': [
            // You can chain multiple strategies
            function(hook) {
                console.log('Hook: ', hook);
            },
            authentication.hooks.authenticate(['jwt', 'local'])
        ],
        'remove': [
            authentication.hooks.authenticate('jwt')
        ]
    }
});

The result of an authentication attempt always results in:

Hook:  { data: 
      { strategy: 'local',
        email: '[email protected]',
        password: 'admin' },
     params: 
      { query: {},
        provider: 'socketio',
        headers: {},
        session: {},
        cookies: {} },
     ...
  }

where the ideal situation would result in:

Hook:  { data: 
      { strategy: 'local',
        email: '[email protected]',
        password: 'admin' },
     params: 
      { query: {},
        provider: 'socketio',
        headers: {},
        session: {},
        cookies: {},
        data: 'Hello world' },
     ...
  }

I have cobbled together a quick fix for my application for the time being. I will clean it up, instrument/test it, and submit a PR to resolve.

thomas-p-wilson added a commit to intellect-collective/feathers-authentication that referenced this issue Apr 9, 2017
…to authentication hooks

Makes those parameters specified in `socket.feathers.data` or `req.feathers.data`, when setting up SocketIO and Primus respectively, available to the authentication hooks as they would be elsewhere in a Feathers application.
ekryski pushed a commit that referenced this issue Apr 11, 2017
…oks (#477)

Makes those parameters specified in `socket.feathers.data` or `req.feathers.data`, when setting up SocketIO and Primus respectively, available to the authentication hooks as they would be elsewhere in a Feathers application.
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

1 participant