Saeven / zf3-circlical-user

Turnkey Authentication, Identity, and RBAC for Laminas and Zend Framework 3. Supports Doctrine and Middleware.
Mozilla Public License 2.0
36 stars 15 forks source link

Is there an easy way to integrate Hybridauth (for Social Logins)? #43

Closed koseduhemak closed 6 years ago

koseduhemak commented 6 years ago

I already have a working login / registration mechanism, but I want to let my users to authenticate also via Facebook Login / Google Login. The module https://github.com/hybridauth/hybridauth looks promising.

However, instead of authenticate via email + password I would need another authentication mechanism based on the social login tokens...

Is there an easy way to integrate such behavior? My first idea would be to extend AuthenticationService and override the authenticate method.

Thank you.

Saeven commented 6 years ago

Hey!

It does look cool, I use a similar approach in software I've created for clients with zf3-circlical-user that need external authentication. The easiest way to go about it, is simply to make the secondary authentication trigger the creation of a standard, unchanged Circlical-user record.

I create a table called 'external_auth'. It contains three columns:

method: e.g., Google, Twitter external_id: The stable Google or Twitter ID that's returned by their auth user_id: An internal, standard user_id

Imagine you have a Controller called TwitterRegistration that understands that a user has logged in. When the success callback comes back in:

  1. Check to see if that method and external_id already has a user binding
  2. If it does, log the user in using the existing data in the user record. You want to resalt the user's auth at this point.

otherwise

  1. Create a new user using Circlical-User (assign a random password)
  2. Create an external_auth record
  3. Repeat the process in #2 above.
koseduhemak commented 6 years ago

Thank you for your extensive answer! I will try your suggestions 👍

Saeven commented 6 years ago

Cool - good luck man!