PHP Class Hybrid_Auth

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.
Mostra file Open project: hybridauth/hybridauth Class Usage Examples

Public Properties

Property Type Description
$config array Configuration array
$error Hybrid_Error Error pool
$logger Hybrid_Logger Logger
$store Hybrid_Storage Auth cache
$version

Public Methods

Method Description
__construct ( array $config ) Try to start a new session of none then initialize Hybrid_Auth
authenticate ( string $providerId, array $params = null ) Try to authenticate the user with a given provider.
getAdapter ( string $providerId = null ) : Hybrid_Provider_Adapter Return the adapter instance for an authenticated provider
getConnectedProviders ( ) : array Return array listing all authenticated providers
getCurrentUrl ( boolean $request_uri = true ) : string Utility function, return the current url
getProviders ( ) : array Return array listing all enabled providers as well as a flag if you are connected
getSessionData ( ) : string | null Get hybridauth session data
initialize ( array $config ) : void Try to initialize Hybrid_Auth with given $config hash or file
isConnectedWith ( string $providerId ) : boolean Check if the current user is connected to a given provider
logoutAllProviders ( ) : void A generic function to logout all connected provider at once
redirect ( string $url, string $mode = "PHP" ) Utility function, redirect to a given URL with php header or using javascript location.href
restoreSessionData ( string $sessiondata = null ) Restore hybridauth session data
setup ( string $providerId, array $params = null ) : Hybrid_Provider_Adapter Setup an adapter for a given provider
storage ( ) : Hybrid_Storage Hybrid storage system accessor

Method Details

__construct() public method

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: http://hybridauth.sourceforge.net/userguide/Configuration.html
public __construct ( array $config )
$config array Configuration array or path to a configratuion file

authenticate() public static method

If the user is already connected we just return and instance of provider adapter, ELSE, try to authenticate and authorize the user with the provider. $params is generally an array with required info in order for this provider and HybridAuth to work, like : hauth_return_to: URL to call back after authentication is done openid_identifier: The OpenID identity provider identifier google_service: can be "Users" for Google user accounts service or "Apps" for Google hosted Apps
public static authenticate ( string $providerId, array $params = null )
$providerId string ID of the provider
$params array Params

getAdapter() public static method

Return the adapter instance for an authenticated provider
public static getAdapter ( string $providerId = null ) : Hybrid_Provider_Adapter
$providerId string ID of the provider
return Hybrid_Provider_Adapter

getConnectedProviders() public static method

Return array listing all authenticated providers
public static getConnectedProviders ( ) : array
return array

getCurrentUrl() public static method

Utility function, return the current url
public static getCurrentUrl ( boolean $request_uri = true ) : string
$request_uri boolean true to get $_SERVER['REQUEST_URI'], false for $_SERVER['PHP_SELF']
return string

getProviders() public static method

array( 'Facebook' => array( 'connected' => true ) )
public static getProviders ( ) : array
return array

getSessionData() public method

Get hybridauth session data
public getSessionData ( ) : string | null
return string | null

initialize() public static method

Try to initialize Hybrid_Auth with given $config hash or file
public static initialize ( array $config ) : void
$config array Configuration array or path to a configratuion file
return void

isConnectedWith() public static method

Check if the current user is connected to a given provider
public static isConnectedWith ( string $providerId ) : boolean
$providerId string ID of the provider
return boolean

logoutAllProviders() public static method

A generic function to logout all connected provider at once
public static logoutAllProviders ( ) : void
return void

redirect() public static method

Utility function, redirect to a given URL with php header or using javascript location.href
public static redirect ( string $url, string $mode = "PHP" )
$url string URL to redirect to
$mode string PHP|JS

restoreSessionData() public method

Restore hybridauth session data
public restoreSessionData ( string $sessiondata = null )
$sessiondata string Serialized session data

setup() public static method

Setup an adapter for a given provider
public static setup ( string $providerId, array $params = null ) : Hybrid_Provider_Adapter
$providerId string ID of the provider
$params array Adapter params
return Hybrid_Provider_Adapter

storage() public static method

Users sessions are stored using HybridAuth storage system ( HybridAuth 2.0 handle PHP Session only) and can be accessed directly by Hybrid_Auth::storage()->get($key) to retrieves the data for the given key, or calling Hybrid_Auth::storage()->set($key, $value) to store the key => $value set.
public static storage ( ) : Hybrid_Storage
return Hybrid_Storage

Property Details

$config public_oe static_oe property

Configuration array
public static array $config
return array

$error public_oe static_oe property

Error pool
public static Hybrid_Error $error
return Hybrid_Error

$logger public_oe static_oe property

Logger
public static Hybrid_Logger $logger
return Hybrid_Logger

$store public_oe static_oe property

Auth cache
public static Hybrid_Storage $store
return Hybrid_Storage

$version public_oe static_oe property

public static $version