volatiletech / authboss

The boss of http auth.
MIT License
3.85k stars 207 forks source link

Processing additional fields during registration #290

Closed johndark closed 4 years ago

johndark commented 4 years ago

Hello.

I need help, please. I want to add authboss into my current project and still don't understand how to intercept the registration event to check additional fields and do some actions with them before the registration occurs. For example, I want to add fingerprint hidden field into the form and when user clicks on Register button I need to get this value and do some action with the database and if all is Ok finish registration by authboss, otherwise return the error message back to the form. How to do it?

aarondl commented 4 years ago

See the implementation in authboss-sample. Look for the "name" field. It is an additional field that uses the PutArbitrary and GetArbitrary methods of the interface.

Additional configuration required is here: https://github.com/volatiletech/authboss-sample/blob/master/blog.go#L108

And here: https://github.com/volatiletech/authboss-sample/blob/master/blog.go#L136-L139 https://github.com/volatiletech/authboss-sample/blob/master/blog.go#L151-L153

johndark commented 4 years ago

Thank you for reply, but that’s not exactly what I need. I asked about callback function for additional fields where I can validate values by my own code.

aarondl commented 4 years ago

So we have our default implementation of a BodyReader here: https://pkg.go.dev/github.com/volatiletech/authboss@v2.4.0+incompatible/defaults?tab=doc#HTTPBodyReader

It takes these rulesets that you can configure yourself but if the Rulesets are not enough for youit'll require a replacement of the default BodyReader implementation entirely.

The body reader's Read returns a Validator which can do what you'd like.

johndark commented 4 years ago

Thank you very much!