Adapter capabilities

 User authenticationYES
 User profileYES
 User contacts listYES
 User feed newsYES
 Post page wallYES
 Access provider APIYES

Adapter specifications

 ID Facebook
 Protocol OAuth 2
 IDp URL http://www.facebook.com/
 Keys registeration https://developers.facebook.com/apps
 Dev documentation http://developers.facebook.com/
 Based on Facebook PHP SDK https://github.com/facebook/php-graph-sdk
 Since HybridAuth 1.0.1
 Wrapper ./Hybrid/Providers/Facebook.php
Callback URL http://mywebsite.com/path_to_hybridauth/?hauth_done=Facebook

Requirements

  • PHP 5.4 or greater
  • Composer (optional)

Installation

Hybridauth can be installed with Composer. Run this command:

composer require hybridauth/hybridauth

However, there are other ways to install hybridauth library:

  1. If you clone hybridauth library and then run composer install:
    • Composer will download facebook/graph-sdk library and generate a vendor/autoload.php file.
    • Hybridauth will include this file and start using the classes that library provides.
  2. If you clone hybridauth library without composer installation (not recommended):
    • You need to download https://github.com/facebook/php-graph-sdk and put it under /Hybrid/thirdparty/ directory.
    • Make sure that /Hybrid/thirdparty/Facebook/autoload.php exists.
    • Hybridauth will include this file and start using the classes that library provides.

Configuration & Usage

<?php
    $config = array(
      "base_url" => "http://mywebsite.com/path/to/hybridauth/",
      "providers" => array (
        "Facebook" => array (
          "enabled" => true,
          "keys"    => array ( "id" => "PUT_YOURS_HERE", "secret" => "PUT_YOURS_HERE" ),
          "scope"   => ['email', 'user_about_me', 'user_birthday', 'user_hometown'], // optional
          "photo_size" => 200, // optional
    )));

    require_once( "/path/to/hybridauth/Hybrid/Auth.php" );

    $hybridauth = new Hybrid_Auth( $config );

    $adapter = $hybridauth->authenticate( "Facebook" );

    $user_profile = $adapter->getUserProfile();

For Facebook you can configure several extra options:

  • scope: An array (or comma-separated list) of permissions you want to request from the user. See the Facebook docs for a full list of available permissions: https://developers.facebook.com/docs/facebook-login/permissions .
    Default: scope = email, public_profile
  • photo_size: The width and height of user picture in pixels. Default: photo_size = 150

Registering application

  1. Go to https://developers.facebook.com/apps and create a new application by clicking "Create New App".
  2. Fill out any required fields such as the application name and description.
  3. Put your website domain in the Site Url field.
  4. Once you have registered, copy and past the created application credentials (App ID and Secret) into the HybridAuth config file.
  5. You also need to add a valid Oauth redirect URI (https://developers.facebook.com/docs/facebook-login/security/). This should be the social login callback url of your website (ie. http://mywebsite.com/path_to_hybridauth/?hauth_done=Facebook). NOTE: The underscore (_) in the callback url. Other HybridAuth callbacks use 'hauth.done', but the Oauth client in the Facebook SDK doesn't accept this.