I’ve been successfully accessing the LinkedIn API through my CodeIngiter application. I moved to a nearly identical server and implemented i18n library and it’s stopped working.
After the user authenticates on LinkedIn it returns to the correct URL, but generates a series of errors beginning with Undefined index: oauth_verifier
After using an i18n library my URLs now have two letter language codes in the 1st segment like ‘en’ or ‘br’.
EDIT: This is the Linkedin library I’m using.
I believe this is causing routing issues with the setting of $_REQUEST[‘oath_verifier’]
Any help on this is greatly appreciated.
Excerpt from controller:
class LinkLogin extends MY_Controller {
function __construct(){
parent::__construct();
$this->load->helper('url');
$this->load->model('profile_model');
$this->load->model('generic_model');
include_once (APPPATH.'libraries/Linkedin.php');
}
function index(){
}
function initiate(){
session_start();
$this->load->helper('url');
$config['linkedin_access'] = "***";
$config['linkedin_secret'] = "***";
$config['base_url'] = "http://www.youinapage.com/linklogin/initiate/";
if ($this->uri->segment(4) == 'profile') {
$config['callback_url'] = "http://www.youinapage.com/linklogin/get_profile_linkedin/";
}
if ($this->uri->segment(4) == 'resume') {
$config['callback_url'] = "http://www.youinapage.com/linklogin/get_resume_linkedin/";
}
function get_resume_linkedin() {
session_start();
$this->load->library('format');
$config['linkedin_access'] = "***";
$config['linkedin_secret'] = "***";
$config['base_url'] = "http://www.youinapage.com/linklogin/initiate/";
$config['callback_url'] = "http://www.youinapage.com/linklogin/get_resume_linkedin/";
# First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
//$linkedin->debug = true;
# First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback
$linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
//$linkedin->debug = true;
if (isset($_REQUEST['oauth_verifier'])){
$_SESSION['oauth_verifier'] = $_REQUEST['oauth_verifier'];
$linkedin->request_token = unserialize($_SESSION['requestToken']);
$linkedin->oauth_verifier = $_SESSION['oauth_verifier'];
$linkedin->getAccessToken($_REQUEST['oauth_verifier']);
$_SESSION['oauth_access_token'] = serialize($linkedin->access_token);
header("Location: " . $config['callback_url']);
exit;
}
else{
$linkedin->request_token = unserialize($_SESSION['requestToken']);
$linkedin->oauth_verifier = $_SESSION['oauth_verifier']; // ERROR: Undefined index: oauth_verifier
$linkedin->access_token = unserialize($_SESSION['oauth_access_token']);
}
Based on your comments and post, I’m guessing you are trying to use the same method twice in a row, so you get logged in. Seems weird but whatever.
The i18n you use will however change your routes to encorporate the languages so you should update your url’s which you are setting inside your to controller to also use that language or a language.
In codeigniter, you should always try to set url’s by the use of
site_url(). This way you can easily port your application to other domainnames/locations. In this case, the localisation-library would also have changed the url’s for you.You should change all references to urls as follows:
To use
site_url(), you will need the URL Helper. You should include that helper before trying to use site_url(). But you already include it in your constructor, so no problems there.You should also replace the use of
header(...); exit;withredirect();. If you die after sending the header, codeigniter will not fully run and your logs will not be fully completed.I would also advice you to check out the manual to check out the build-in session class and the input class.