2

I am currently using hybridauth for the integration of social login in a website. The websites url is find.pk. I have added Facebook, Twitter, Google+ and Microsoft login in the site and they work perfectly. But the linkedin one just redirects me to the hybridauth root page after taking username and password. Means here: find.pk/public/social/hybridauth this is also defined as the base url the config file.

ROOT / public / social / hybridauth /   ( The path of the hybridauth lib ) 

and

ROOT / pubilc / social / all.php?login={whateverprovider} ( To authenticate using any provided e.g facebook, twitter etc. )  

You can see the live demo for linkedin login problem:

find.pk/public/social/all.php?login=linkedin

all.php code:

<?php
session_start();
if (isset( $_GET['login'] ))
{
    switch ($_GET['login']) {
        case 'facebook':

        // Now Login with facebook
        $config = "hybridauth/config.php";

        require_once( "hybridauth/Hybrid/Auth.php" );

        $hybridauth = new Hybrid_Auth( $config );

        $adapter = $hybridauth->authenticate( "Facebook" ); 
        $user_profile = $adapter->getUserProfile(); 
        $user_profile = json_decode(json_encode( $user_profile ));
        $_SESSION['social_profile'] = $user_profile;
        header("Location: http://find.pk/user/social_got");
        exit;


        break;

        case 'twitter':

        $config = "hybridauth/config.php";

        require_once( "hybridauth/Hybrid/Auth.php" );

        $hybridauth = new Hybrid_Auth( $config );

        $adapter = $hybridauth->authenticate( "Twitter" ); 
        $user_profile = $adapter->getUserProfile(); 
        $user_profile = json_decode(json_encode( $user_profile ));
        $_SESSION['social_profile'] = $user_profile;
        header("Location: http://find.pk/user/social_got");
        exit;
        break;

        case 'linkedin':

        $config = "hybridauth/config.php";

        require_once( "hybridauth/Hybrid/Auth.php" );

        $hybridauth = new Hybrid_Auth( $config );

        $adapter = $hybridauth->authenticate( "LinkedIn" ); 
        $user_profile = $adapter->getUserProfile();
        $user_profile = json_decode(json_encode( $user_profile ));
        $_SESSION['social_profile'] = $user_profile;
        header("Location: http://find.pk/user/social_got");
        exit;

        break;


        case 'google':
        $config = "hybridauth/config.php";

        require_once( "hybridauth/Hybrid/Auth.php" );

        $hybridauth = new Hybrid_Auth( $config );

        $adapter = $hybridauth->authenticate( "Google" ); 
        $user_profile = $adapter->getUserProfile();
        $user_profile = json_decode(json_encode( $user_profile ));
        $_SESSION['social_profile'] = $user_profile;
        header("Location: http://find.pk/user/social_got");
        exit;

        break;

        case 'live':
        $config = "hybridauth/config.php";

        require_once( "hybridauth/Hybrid/Auth.php" );

        $hybridauth = new Hybrid_Auth( $config );

        $adapter = $hybridauth->authenticate( "Live" ); 
        $user_profile = $adapter->getUserProfile();
        $user_profile = json_decode(json_encode( $user_profile ));
        $_SESSION['social_profile'] = $user_profile;
        header("Location: http://find.pk/user/social_got");
        exit;

        break;

        default:
            # code...
            break;
    }

    exit;
}
Llewellyn Collins
  • 2,243
  • 2
  • 23
  • 37
user3151422
  • 111
  • 1
  • 1
  • 3

1 Answers1

1

Simple Solution

Go to this file: hybridauth/Hybrid/Thirdparty/LinkedIn/LinkedIn.php (may have different path in your case)

Go to line 126 where _URL_REQUESTis defined.

Change this line to this:

const _URL_REQUEST                 = 'https://api.linkedin.com/uas/oauth/requestToken?scope=r_basicprofile+r_emailaddress+w_share'; 

Details:

The linkedin have made changes to developers programs. so they have changed parameters for requests.

Details can be read here.

The main issue is the parameters we are sending with request.

The most prominent is rw_nus which is now deprecated. instead use the w_share

captain_a
  • 3,328
  • 1
  • 14
  • 23