joscha / play-authenticate

An authentication plugin for Play Framework 2.x (Java)
http://joscha.github.com/play-authenticate/
Other
807 stars 366 forks source link

Can I use two different Authentication Providers for different users? #170

Closed jaybytez closed 10 years ago

jaybytez commented 10 years ago

I am using the play-authenticate-usage sample classes for my application to allow me to provide email based login (along with OAuth providers), and this works great!

I have admins that I want to use a unique id (like a taxid) instead of email, so I started creating different login/signup forms for them.

Based on this closed issue:

https://github.com/joscha/play-authenticate/issues/69

Would I have to duplicate the 3 classes within the provider in order to create an alternate authentication path that uses a taxid or username as the login, but still uses the email address for communications of password resets and verification emails.

Thanks...jay

jaybytez commented 10 years ago

I was able to accomplish this finally.

I duplicate the 4 classes under the core play-authenticate framework for usernamepassword and called the uniqueid. I created a UniqueIdIdentity where the field was Long uniqueId. I changed all the references that utilize the email as a key to be the uniqueId and left all the email functionality for sending emails of course. Then I duplicated the 3 classes from the play sample like MyUsername* and DefaultMy* and changed them so they inherited from the 4 new UniqueId Provider classes that I created. I had to remember that in the Default class to change the Override of the getId to return the getUniqueId instead of the getEmail...otherwise the getSession instance of the class would return the original getId in the base class which is the password (and therefore the User class would be unable to find an instance of that User). I also created duplicate classes for Signup and Account, one that was based off the email login and one of the uniqueid login. I also had to create duplicate routes then as well so that I could have 2 login pages, 2 signup pages, and the other html files that won't compile once I duplicate the Signup controller. If you want a sample of the code, just let me know and I can share the base classes. It might not be the right way, but with only code to go by, it was pretty much trial and error.