feathers-authentication version 1 app.authenticate not working with sockets

↘锁芯ラ 提交于 2020-01-05 05:04:09

问题


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.



来源:https://stackoverflow.com/questions/42538683/feathers-authentication-version-1-app-authenticate-not-working-with-sockets

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!