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

Make `socket.feathers` data available in authentication hooks #475

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

Comments

Projects
None yet
1 participant
@thomas-p-wilson
Copy link
Contributor

thomas-p-wilson commented Apr 9, 2017

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: 'admin@feathersjs.com',
        password: 'admin' },
     params: 
      { query: {},
        provider: 'socketio',
        headers: {},
        session: {},
        cookies: {} },
     ...
  }

where the ideal situation would result in:

Hook:  { data: 
      { strategy: 'local',
        email: 'admin@feathersjs.com',
        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

Resolves feathersjs#475 - Socket params are made available to authent…
…ication 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 ekryski closed this in #477 Apr 11, 2017

ekryski added a commit that referenced this issue Apr 11, 2017

Resolves #475 - Socket params are made available to authentication ho…
…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 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.