A trend in many of today’s websites is a feature that allows users to sign in via their social network accounts. A classic example is the SitePoint community where users have the option to use their Facebook, Twitter, Google, Yahoo or GitHub account to log in without having to register an account.
In this tutorial, we will be learning about HybridAuth – a PHP library that takes the pain out of building a social login feature.
HybridAuth acts as an abstract API between your application and the various social APIs and identity providers.
Installation
The recommended way to install HybridAuth is via Composer. We’ll also use Slim as a foundation for our sample app.
To use HybridAuth, copy the config.php and index.php (HybridAuth Endpoint) files in /vendor/hybridauth/hybridauth/hybridauth to your project’s root folder.
Rename the index.php file to hybrid.php because index.php will be used by Slim framework for our demo application logic.
Populate the config.php file with your application’s (e.g. Facebook, Twitter application) credentials.
For example, If you want users to sign in to your website via Facebook, Google, and Twitter; your config file would look pretty much like this. My application URL is http://slim.local.
Hybrid_Endpoint::process(); is a core hybrid method that calls the appropriate methods to process a social login authentication.
Since we are routing the auth request to hybrid.php, the method need to be in the file. For instance, when you download the hybridauth library, all examples are routend to index.php. open the file and you will see it inside.
It’s almost the same - it’s identical up until the “Application logic” part which will differ for every non-Slim app. That’s where your own router and your own controller logic will be taking over, so we can’t help with that part