Hybrid_Auth::authenticate PHP Method

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
    public static function authenticate($providerId, $params = null)
    {
        Hybrid_Logger::info("Enter Hybrid_Auth::authenticate( {$providerId} )");
        if (!Hybrid_Auth::storage()->get("hauth_session.{$providerId}.is_logged_in")) {
            // if user not connected to $providerId then try setup a new adapter and start the login process for this provider
            Hybrid_Logger::info("Hybrid_Auth::authenticate( {$providerId} ), User not connected to the provider. Try to authenticate..");
            $provider_adapter = Hybrid_Auth::setup($providerId, $params);
            $provider_adapter->login();
        } else {
            // else, then return the adapter instance for the given provider
            Hybrid_Logger::info("Hybrid_Auth::authenticate( {$providerId} ), User is already connected to this provider. Return the adapter instance.");
            return Hybrid_Auth::getAdapter($providerId);
        }
    }

Usage Example

Esempio n. 1
3
 public function getGoogleLogin($auth = NULL)
 {
     if ($auth == 'auth') {
         Hybrid_Endpoint::process();
     }
     try {
         $oauth = new Hybrid_Auth(app_path() . '/config/google_auth.php');
         $provider = $oauth->authenticate('Google');
         $profile = $provider->getUserProfile();
     } catch (exception $e) {
         return $e->getMessage();
     }
     if ($user = User::where('email', '=', $profile->email)->first()) {
         Auth::login($user, true);
         return Redirect::intended('/');
     }
     return App::make('frontend\\UserController')->doSignUp(array('email' => $profile->email, 'login' => $profile->identifier, 'password' => "pass1234", 'f_name' => $profile->firstName, 'l_name' => $profile->lastName));
 }
All Usage Examples Of Hybrid_Auth::authenticate