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:
- $config_array = array(
- "base_url" => "http://mywebsite.com/path/to/hybridauth/",
- "providers" => array (
- "Twitter" => array (
- "enabled" => true, "keys" => array ( "key" => "", "secret" => "" )
- ),
- "Facebook" => array (
- "enabled" => true, "keys" => array ( "id" => "", "secret" => "" )
- ),
- "OpenID" => array (
- "enabled" => true
- )
- )
- );
- $hybridauth = new Hybrid_Auth( $config_array );
Ex2: Initialize Hybrid_Auth
with a configuration file path:
- $config_file_path = '/path/to/library/hybridauth.php';
- $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.
- 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. :
|
getAdapter()
Return the adapter instance of an authenticated provider adapter Hybrid_Provider_Adapter
.
- 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.
- 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.
- 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
.
- Hybrid_Auth::getSessionData()
restoreSessionData()
Restore HybridAuth session from a given [serialized] array
.
- Hybrid_Auth::restoreSessionData(
array
)
logoutAllProviders()
A generic function to logout all connected providers at once.
- Hybrid_Auth::logoutAllProviders()
redirect()
Utility function, redirect to a given url
with php header function
- Hybrid_Auth::redirect(
url
)
getCurrentUrl()
Utility function, return the current url of the request web page.
- 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.
- // hybridauth will try to authenticate the user, then return an instance of Twitter adapter
- $twitter_adapter = $hybridauth->authenticate( "Twitter" );
- // get the user profile
- $twitter_user_profile = $twitter_adapter->getUserProfile();
- // disconnect the user form twitter
- $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.
- Hybrid_Provider_Adapter::isUserConnected()
getUserProfile()
Return an instance of Hybrid_User_Profile
an object which represents the current logged in user profile
- 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.
- 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.
- 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.
- 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
- Hybrid_Provider_Adapter::logout()
getAccessToken()
Return the current oauth access.token
for the provider if the provider is using OAuth protocol.
- Hybrid_Provider_Adapter::getAccessToken()
api()
Return an instance of the provider api if any
- 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.
- // try to authenticate the user with Twitter
- $twitter_adapter = $hybridauth->authenticate( "Twitter" );
- // get the user profile
- $twitter_user_profile = $twitter_adapter->getUserProfile();
- // debug the received user profile
- print_r( $twitter_user_profile );
- // echo the user profile page on twitter >> http://twitter.com/<username>
- 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. |
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. |