volatiletech / authboss

The boss of http auth.
MIT License
3.79k stars 204 forks source link

Validate email address with ParseAddress #345

Open darksnow opened 1 year ago

darksnow commented 1 year ago

Is it possible to validate email addresses using the Go built in ParseAddress function instead of a regexp?

Looking at https://cs.opensource.google/go/go/+/master:src/net/mail/message.go shows how complex correctly validating an email address is but I can't see a way to use that function in Authboss, or any regexp in the above code that I can apply to MustMatch.

Perhaps a good solution could be to add a ValidationFunction option to Rules which takes a func(string) bool

Botino888 commented 1 year ago

https://cs.opensource.google/go/go/+/master:src/net/mail/message.go https://cs.opensource.google/go/go/+/master:src/net/mail/message.go;drc=b2faff18ce28edad98303d2c3134dec1331fd7b5 src/net/mail/message.go open-pull-requests-limit

aarondl commented 1 year ago

Sounds like a good idea.

I think we could add a bool to opt out of this functionality, but have it turned on by default and use our license for breaking changes to introduce this in a minor. It shouldn't be processing invalid ones already. Welcome a PR for this.