feathersjs / docs

[MOVED] Legacy Feathers documentation
https://crow.docs.feathersjs.com/
MIT License
242 stars 531 forks source link

Comment: Anonymous authentication (cookbook/authentication/anonymous.md) #1458

Closed egtzori closed 4 years ago

egtzori commented 4 years ago

Comment/Problem

I need anonymous login for my project and i followed every step here and on internet. Error i get is: "Invalid authentication information (strategy not allowed in authStrategies)"

I have: authentication.register('anonymous', new AnonymousStrategy()); and i see it in console.log(authentication);

anonymous:
AnonymousStrategy {
name: 'anonymous',
app: [EventEmitter],
authentication: [Circular] } },

but no matter what i try i get that error. Client side i try to: user = await client.authenticate({strategy: 'anonymous', name: credentials.email, email: 'asd', password: '123', room: '1'}); .. and every possible combination i could try.. it will just say that there is no such strategy.

this is my authentication.js:

const { AuthenticationService, JWTStrategy, AuthenticationBaseStrategy  } = require('@feathersjs/authentication');
const { LocalStrategy } = require('@feathersjs/authentication-local');
const { expressOauth } = require('@feathersjs/authentication-oauth');

class AnonymousStrategy extends AuthenticationBaseStrategy {
  async authenticate(authentication, params) {
    return {
      anonymous: true
    }
  }
}

module.exports = app => {
  const authentication = new AuthenticationService(app);

  authentication.register('jwt', new JWTStrategy());
  authentication.register('local', new LocalStrategy());
  authentication.register('anonymous', new AnonymousStrategy());

  app.use('/authentication', authentication);
  app.configure(expressOauth());
}

Also, postman request POST /authenticate { "strategy": "anonymous"} returns: "message": "Invalid authentication information (strategy not allowed in authStrategies)",

System configuration (optional)

Module versions (especially the part that's not working):

    "feathers"
    "@feathersjs/authentication": "^4.5.2",
    "@feathersjs/authentication-local": "^4.5.2",
    "@feathersjs/authentication-oauth": "^4.5.2",
    "@feathersjs/configuration": "^4.5.2",
    "@feathersjs/errors": "^4.5.2",
    "@feathersjs/express": "^4.5.2",
    "@feathersjs/feathers": "^4.5.2",
    "@feathersjs/socketio": "^4.5.2",
    "@feathersjs/transport-commons": "^4.5.2",
    "feathers-memory": "^4.1.0",
    "feathers-nedb": "^5.1.0",

NodeJS version: v12.16.0

Operating System: Windows 10

Browser Version: Chrome latest

daffl commented 4 years ago

You do not need to call app.authenticate with the anonymous strategy. It will be used automatically if no other authentication information is used.