17

I was trying to make HybridAuth Social Login work on this simple php site. Downloaded HybridAuth and installed it. Then found that even the examples does not work for social login (tried on remote server too.

The normal signin_signup example works fine. But whenever I click the link to login to a social network (i.e, facebook,twitter) it redirects me to (MY_BASE_URL/index.php?hauth.start=Facebook&hauth.time) without showing any login window/error messages at all.

I've carefully read the documentations and other solutions posted here. Adjusted my config.php to have a base url like http://example.com/index.php . But it just does not respond. Is there something I'm missing? I've spent 2 days already on it.

here is my config.php

return 
    array(
        "base_url" => "http://example.com/index.php", 

        "providers" => array ( 
            // openid providers
            "OpenID" => array (
                "enabled" => false
            ),

            "AOL"  => array ( 
                "enabled" => false 
            ),

            "Yahoo" => array ( 
                "enabled" => false,
                "keys"    => array ( "id" => "", "secret" => "" )
            ),

            "Google" => array ( 
                "enabled" => true,
                "keys"    => array ( "id" => "", "secret" => "" )
            ),

            "Facebook" => array ( 
                "enabled" => true,
                "keys"    => array ( "id" => "xxxxxxxxx", "secret" => "xxxxxxx" )
            ),

            "Twitter" => array ( 
                "enabled" => true,
                "keys"    => array ( "key" => "xxxxxxxx", "secret" => "xxxxxxxx" ) 
            ),

            // windows live
            "Live" => array ( 
                "enabled" => false,
                "keys"    => array ( "id" => "", "secret" => "" ) 
            ),

            "MySpace" => array ( 
                "enabled" => false,
                "keys"    => array ( "key" => "", "secret" => "" ) 
            ),

            "LinkedIn" => array ( 
                "enabled" => true,
                "keys"    => array ( "key" => "xxxxxxxx", "secret" => "xxxxxxx" ) 
            ),

            "Foursquare" => array (
                "enabled" => false,
                "keys"    => array ( "id" => "", "secret" => "" ) 
            ),
        ),

        // if you want to enable logging, set 'debug_mode' to true  then provide a writable file by the web server on "debug_file"
        "debug_mode" => false,

        "debug_file" => ""
    );

Can someone please help me? I got a feeling that it does not work very good at all after searching the internet for quite a long. If that's the case, can someone point to a better alternative opensource/free social signin library?

tintinboss
  • 672
  • 1
  • 7
  • 25

5 Answers5

23

Further to tintinboss's own answer, I found I needed to check for hauth_done as well (this was for an example testing Facebook):

if (isset($_REQUEST['hauth_start']) || isset($_REQUEST['hauth_done']))
{
    Hybrid_Endpoint::process();
}

This finally got it working - thank you tintinboss for the useful answer!

johnsyweb
  • 136,902
  • 23
  • 188
  • 247
Rick
  • 1,136
  • 11
  • 10
20

Alright, I've solved it myself.

As stated before, the documentation was really not good. Here's the solution for anyone who wants to integrate this code in future

Firstly, you have to make your baseurl like this in config.php

"base_url" => "http://yoursite.com/subdomain/index.php", OR

"base_url" => "http://yoursite.com/index.php",

Note that I'm not using www. Don't know why, but it does not work with www.

Now the tricky part, you have to include this in your index.php file

require_once( "PATH_TO_HYBRID/Auth.php" );
require_once( "PATH_TO_HYBRID/Endpoint.php" ); 

if (isset($_REQUEST['hauth_start']))
        {
            Hybrid_Endpoint::process();

        }

The Endpoint Process is what makes you redirect to a blank page if not provided. And you must add it to the index.php as far as I've tested.

Now the code should work fine :) I'll be happy if it helps someone.

tintinboss
  • 672
  • 1
  • 7
  • 25
  • 6
    Thanks. I've no idea why such trivial things as 'working demos' seem to elude people. Yes, I know not every scenario can always be covered, but I'm not sure I would have ever found Hybrid_Endpoint::process() on my own. Also, I'll throw in that for Google, at least, it requires registered redirect urls, and the ?hauth.done=Google needs to be part of your registered redirect with Google, as far as I can tell (only way it worked for me). Again, thanks. – kimsal Jun 23 '13 at 21:25
  • Also having www in the page url you're trying to test on spanners it as well. – Ally Jul 28 '13 at 15:21
  • Spent hours to figure out why I wasn't redirected and only receiving `"class" not found`. I've even removed all .htaccess rules and cleared my auto loading schema to find out I only had to remove 'www.' from the base url... Your answer is highly appreciated! Thank you. – Ben Fransen Aug 19 '15 at 07:44
  • I did exactly you mentioned it but still not working. It goes http://localhost/social_process.php#_=_ and stucks there. – user20072008 Oct 12 '15 at 16:31
7

@tintinboss and @dJomp answers sorted me out. however I still needed to get info out of the logged in user, which took me long indeed. Here I share the final version that will get you far away from this awful loop.

$config = require 'config.php';
require_once( "Hybrid/Auth.php" );
require_once( "Hybrid/Endpoint.php" );

if (isset($_REQUEST['hauth_start']) || isset($_REQUEST['hauth_done'])) {
    Hybrid_Endpoint::process();
} else {
    try {
        $hybridauth = new Hybrid_Auth( $config );
        $google = $hybridauth->authenticate( "Google");
        $user_profile = $google->getUserProfile();

        echo "Hi there! " . $user_profile->email; 
    } catch( Exception $e ){
        echo "Ooophs, we got an error: " . $e->getMessage();
    }
}
2682562
  • 139
  • 2
  • 6
1

Hi I have tried all the solution suggestions of this problem but none have reached the solution. I solved the problem like this.

"base_url" => 'http://'.$_SERVER['SERVER_NAME'].'inauth/auth',

The key point here is the server name.In addition, cookies are recording your sessions and you can not preview changes you've made. Clear cookies and try again.

T.Arslan
  • 123
  • 8
0

We are using nginx and we fixed it by adding ?$args to our location block. Without it, the request does not pass hauth_done.

location / {
    try_files $uri $uri/ /index.php?$args;
}
Springfire
  • 1
  • 1
  • 1