feathers-authentication version 1 app.authenticate

2019-07-29 05:52发布

问题:

I have setup feathersjs with ldap authentication, which requires feathers-authentication version 1. It works fine over rest using app.authenticate but it fails when using sockets. After enabling debugging, I confirmed that the server gets the credentials and successfully generates the token. The client, however, is not able to get the response. The server is emitting 'authentication created' which the client gets only when using socket.on('authentication created') not when using app.authenticate(). I know I can use plain socket and get the job done but the docs recommend using app.authenticate and then use app.service('someService').

The following snippet works fine with rest but not with socket.

app.authenticate({
  type: 'local',
  endpoint: '/authentication',
  strategy: 'ldap',
  'username': 'user',
  'password': 'password'
}).then(function(result){
  console.log('Authenticated!', app.get('token'));
}).catch(function(error){
  console.error('Error authenticating!', error);
});

This is how I setup sockets:

var socket = io(apiDomain, {
  transport: ['websockets']
});

// Set up Feathers client side
var app = feathers()
.configure(feathers.socketio(socket))
.configure(feathers.hooks())
.configure(feathers.authentication({ storage: window.localStorage }));

回答1:

feathers-authentication version 1.x only works with the feathers-client v2.0.0-pre.1 or later. This is currently still a prerelease and has to be installed accordingly (npm install feathers-client@pre --save) or by loading the individual module feathers-authentication-client using a module loader.



标签: feathersjs