senecajs / seneca-auth

A Seneca user authentication plugin for Hapi and Express
http://senecajs.org
MIT License
33 stars 29 forks source link

Chairo + Auth are broken #69

Closed mcdonnelldean closed 8 years ago

mcdonnelldean commented 8 years ago

@geek Updated to Chairo 2.0, now none of my auth stuff is working, detail below,

Message: seneca: Action role:web failed: Unknown authentication strategy session in /auth/logout.

Code: act_execute

Details: { id: 'u80225qqhsi5/bmob22drdesd',
 gate: false,
 ungate: true,
 desc: undefined,
 cb: [Function: noop],
 fn: { [Function: web_use] validate: { use: {}, config: {}, plugin: {} } },
 time: { start: 1454783485508 },
 'orig$': [Error: Unknown authentication strategy session in /auth/logout],
 'message$': 'Unknown authentication strategy session in /auth/logout',
 message: 'Unknown authentication strategy session in /auth/logout',

If I remove the auth stuff chairo works ask expected so I think the issue is either in seneca-web or the auth related plugins. @mirceaalexandru as has a number of branches outstanding for seneca-auth-*.

Some combination of branches has worked but now I can't be sure. Can we get some eyes on this as priority? This is my script,

'use strict'

module.exports = (opts, server, done) => {
  var seneca = server.seneca
    //.use('user') // Note: swap this out for local concorda
    //.use('auth', {restrict: '/api'})
    .use('stats', {collector: true})
    .use('toolbag-stats')
    .use('influx-stats-store', {influx: {host: '192.168.99.100'}})

  seneca.act({
    role: 'user',
    cmd: 'register',
    name: opts.admin.name,
    email: opts.admin.email,
    password: opts.admin.password
  })

  seneca.ready(() => {
    seneca.log.info('hapi', server.info.port)
    server.start(done)
  })
}

Note: By commenting out the lines above chairo works but now I am missing my auth. Also I'm not using Concorda in this instance, it's just auth, user, and local login.

geek commented 8 years ago

@mcdonnelldean looks like auth needs to be updated to export a preload function:

module.exports.preload = function () {
  return {
    name: 'auth'
  }
}
mirceaalexandru commented 8 years ago

@geek

I moved all required code into init function that now is something like this:

........

  seneca.add('init: auth', init)

  return {
    name: 'auth'
  }
}

This was a fix but most important - and the reason for the above error - is that now I used seneca.ready() like this:

    seneca.use(AuthToken, internals.options)
    seneca.use(AuthUrlmatcher, internals.options)
    seneca.use(Utility, internals.options)
    seneca.use(UserManagement, internals.options)
    seneca.use(AuthRedirect, internals.options.redirect || {})

    seneca.ready(function(){
      seneca.use(HapiAuth, internals.options)
      seneca.use(LocalStrategy, internals.options)
    })

Because I need to be sure that before HapiAuth & LocalStrategy are loaded all other plugins are fully initialized. Please let me know if it is a correct approach.

mirceaalexandru commented 8 years ago

@geek this is fixed with latest PR being merged into master.

geek commented 8 years ago

@mirceaalexandru do you have a link to the PR ?

mirceaalexandru commented 8 years ago

@geek, is now merged into master, just minutes ago.

mcdonnelldean commented 8 years ago

@geek @mirceaalexandru Let me know when this is all on releases and I will update Vidi

mirceaalexandru commented 8 years ago

@mcdonnelldean you can use for now master from seneca-auth, not from my account. There are two issues to be fixed, then I think we can publish it.

mirceaalexandru commented 8 years ago

We can close this