adonisjs / auth

Official Authentication package for AdonisJS
https://docs.adonisjs.com/guides/auth/introduction
MIT License
196 stars 63 forks source link

two JWT schemes: Exception doesnt parse needed auth config #75

Closed outluch closed 6 years ago

outluch commented 6 years ago

I have 2 types of users and auth systems respectfully: client lgged in by phone number and unique device id, and operator, who work on orders, received from clients. Operators should log in with email/password or maybe username/password. More classical. How can I define two JWT schemes? Or I should write my own implementation for one of schemes? (or copy from adonis auth middleware?

outluch commented 6 years ago

Yo. Actually it is kind of working. I just copy-pasted jwt scheme in auth config. And used it like auth.authenticator('sms').attempt(phone, uuid). All tests pass excluding one, checking for error when attempt is failed. (eg wrong phone provided. Look at my code: config/auth.js

authenticator: 'jwt', (default authenticator)
...
sms: {
    serializer: 'lucid',
    model: 'App/Models/Client',
    scheme: 'jwt',
    uid: 'phone',
    password: 'uuid',
    options: {
      secret: 'self::app.appKey',
    },
  },

  jwt: {
    serializer: 'lucid',
    model: 'App/Models/User',
    scheme: 'jwt',
    uid: 'email',
    password: 'password',
    options: {
      secret: 'self::app.appKey',
    },
  },

And in controller:

  async login({ request, response, auth }) {
    const { phone, uuid } = request.all()
    return auth.authenticator('sms').attempt(phone, uuid)
  }

Despite I set my sms authenticator, error handler just takes dafault config and generates error from its uid/password fields. I think it is error. https://github.com/adonisjs/adonis-auth/blob/046610960bddfa20a6f256922fd458a0bda5e3d0/src/Exceptions/index.js#L44

thetutlage commented 6 years ago

Yup seems like a bug 🐛

thetutlage commented 6 years ago

Mind checking it from the develop branch of github and see if it reports with right errors?

outluch commented 6 years ago

Thanks. Will try a bit later, maybe weekend. Now quite busy.