HybridAuth
  • Documentation
  • API
  • Help & Support
  • Plugins
  • Download
Fork me on GitHub

Note: This documentation only describe classes, functions and attributes you will use throughout your application. Download this API documentation »

Hybrid_Auth Hybrid/Auth.php

Hybrid_Auth class provide a simple way to authenticate users via OpenID and OAuth.

Generally, Hybrid_Auth is the only class you should instanciate and use throughout your application.

Using Hybrid_Auth

Hybrid_Auth constructor will require either a valid config array or a path for a configuration file as parameter. To know more please refer to the Configuration section.


Ex1: Initialize Hybrid_Auth with an array:

  1. $config_array = array(
  2. "base_url" => "http://mywebsite.com/path/to/hybridauth/",
  3. "providers" => array (
  4. "Twitter" => array (
  5. "enabled" => true, "keys" => array ( "key" => "", "secret" => "" )
  6. ),
  7. "Facebook" => array (
  8. "enabled" => true, "keys" => array ( "id" => "", "secret" => "" )
  9. ),
  10. "OpenID" => array (
  11. "enabled" => true
  12. )
  13. )
  14. );
  15.  
  16. $hybridauth = new Hybrid_Auth( $config_array );

Ex2: Initialize Hybrid_Auth with a configuration file path:

  1. $config_file_path = '/path/to/library/hybridauth.php';
  2.  
  3. $hybridauth = new Hybrid_Auth( $config_file_path );

Constructor options

Name type description
config array, string It can be a config array or the path of a configuration file

Methods

authenticate()

Try to authenticate the user with a given provider.

If the user is already connected we just return and instance of the provider adapter Hybrid_Provider_Adapter, ELSE, try to authenticate and or authorize the user with this provider.

When a user login via a given provider using Hybrid_Auth::authenticate(), HybridAuth Library creates a login session for the user. By default the session and will stay as long as the current PHP Sessions is still active or until Hybrid_Provider_Adapter::logout() method is called. To know more refer to the HybridAuth Sessions section.

  1. Hybrid_Auth::authenticate( provider, params )
Name type description
provider string $provider is an the provider name to connect to.
params optional, array $params is an Optional array which generally contain some extra info in order for the provider to work, Ex. :
  • hauth_return_to: URL to call back after authentication is done
  • openid_identifier: The OpenID identity provider identifier

getAdapter()

Return the adapter instance of an authenticated provider adapter Hybrid_Provider_Adapter.

  1. Hybrid_Auth::getAdapter(provider)

isConnectedWith()

Return a true or false if the current user is connected to a given provider. Hybrid_Auth::isConnectedWith() use PHP Sessions. To know more refer to the HybridAuth Sessions section.

  1. Hybrid_Auth::isConnectedWith(provider)

getConnectedProviders()

Return list of Authenticated providers. Hybrid_Auth::getConnectedProviders() use PHP Sessions. To know more refer to the HybridAuth Sessions section.

  1. Hybrid_Auth::getConnectedProviders()

getSessionData()

Get the session stored data. To be used on case you want to store session on a more persistent backend. Return a serialized array.

  1. Hybrid_Auth::getSessionData()

restoreSessionData()

Restore HybridAuth session from a given [serialized] array.

  1. Hybrid_Auth::restoreSessionData(array)

logoutAllProviders()

A generic function to logout all connected providers at once.

  1. Hybrid_Auth::logoutAllProviders()

redirect()

Utility function, redirect to a given url with php header function

  1. Hybrid_Auth::redirect(url)

getCurrentUrl()

Utility function, return the current url of the request web page.

  1. Hybrid_Auth::getCurrentUrl()

Hybrid_Provider_Adapter Hybrid/Provider_Adapter.php

Hybrid_Provider_Adapter is the basic class which Hybrid_Auth will use to connect users to a given provider. Basically Hybrid_Provider_Adapter will create a bridge from your php application to the provider api.

There is a different Adapter for each providers HybridAuth support.

Hybrid_Auth will automatically load Hybrid_Provider_Adapter and create an instance of it for each authenticated provider.

  1. // hybridauth will try to authenticate the user, then return an instance of Twitter adapter
  2. $twitter_adapter = $hybridauth->authenticate( "Twitter" );
  3.  
  4. // get the user profile
  5. $twitter_user_profile = $twitter_adapter->getUserProfile();
  6.  
  7. // disconnect the user form twitter
  8. $twitter_adapter->logout();

Methods

isUserConnected()

Return true if the user is authenticate with the provider or false if not. Hybrid_Provider_Adapter::isUserConnected() use PHP Sessions. To know more refer to the HybridAuth Sessions section.

  1. Hybrid_Provider_Adapter::isUserConnected()

getUserProfile()

Return an instance of Hybrid_User_Profile an object which represents the current logged in user profile

  1. Hybrid_Provider_Adapter::getUserProfile()

setUserStatus()

Update the user status or post to his wall across social networks.
Currently not all providers support this feature. Please refer to Update User Status section to know more.

  1. Hybrid_Provider_Adapter::setUserStatus( $status )
Name type description
status string $status is the user status to send to the social service

getUserContacts()

Provide the connected user contact list's in a rich, simple and standardized structure across social networks.
Currently not all providers support this feature. Please refer to Access User Contacts section to know more.

  1. Hybrid_Provider_Adapter::getUserContacts()

getUserActivity()

Provide the connected user and his friends activity stream in simple and standardized structure across social networks.
Currently not all providers support this feature. Please refer to Access User Contacts section to know more.

  1. Hybrid_Provider_Adapter::getUserContacts( $stream )
Name type description
stream string $stream can be "timeline" to get all the stream or "me" to load the user activity only

logout()

Let hybridauth forget all about the current user ONLY for this provider

  1. Hybrid_Provider_Adapter::logout()

getAccessToken()

Return the current oauth access.token for the provider if the provider is using OAuth protocol.

  1. Hybrid_Provider_Adapter::getAccessToken()

api()

Return an instance of the provider api if any

  1. Hybrid_Provider_Adapter::api()

Properties

Name type description
id string Provider ID (or name)
config array Provider config
params array Provider paramameters

Hybrid_User_Profile Hybrid/User/Profile.php

Hybrid_User_Profile object represents the current logged in user profile. list of fields available in the normalized user profile structure used by HybridAuth. The Hybrid_User_Profile object is populated with as much information about the user as HybridAuth was able to pull from the given API or authentication provider.

  1. // try to authenticate the user with Twitter
  2. $twitter_adapter = $hybridauth->authenticate( "Twitter" );
  3.  
  4. // get the user profile
  5. $twitter_user_profile = $twitter_adapter->getUserProfile();
  6.  
  7. // debug the received user profile
  8. print_r( $twitter_user_profile );
  9.  
  10. // echo the user profile page on twitter >> http://twitter.com/<username>
  11. echo $twitter_user_profile->profileURL;

Properties

Name type description
identifier  String The Unique user's ID on the connected provider. Can be an interger for some providers, Email, URL, etc.
profileURL  String URL link to profile page on the IDp web site
webSiteURL  String User website, blog, web page,
photoURL  String URL link to user photo or avatar
displayName  String User dispalyName provided by the IDp or a concatenation of first and last name.
description  String A short about_me
firstName  String User's first name
lastName  String User's last name
gender  String User's gender. Values are 'female', 'male' or NULL
language  String User's language
age  Integer User' age, note that we dont calculate it. we return it as is if the IDp provide it
birthDay  Integer The day in the month in which the person was born.
birthMonth  Integer The month in which the person was born.
birthYear  Integer The year in which the person was born.
email  String User email. Not all of IDp garant access to the user email
emailVerified  String Verified user email. Note: not all of IDp garant access to verified user email.
Added since version 2.0.11. Currently only Facebook, Google, Yahoo and Foursquare do provide the verified user email.
phone  String User's phone number
address  String User's address
country  String User's country
region  String User's state or region 
city  String User's city
zip  Integer Postal code or zipcode.

HybridAuth Open Source PHP Social Sign On Library, © 2009-2015.

Code licensed under dual licence MIT and GPLv3, documentation under CC BY 4.0.

HybridAuth website was made using Bootstrap and jQuery. Project hosting provided by Github.