php superglobal function ($GLOBALS['headers']['Authorization']) in never set. why? - php

I have php function that is supposed to verify if there is a token, and if so, search my table for a company name that matches. The function works fine when I use xampp in localhost. When I do it in prod on the server, it gives me a 'token undefined' error, What could possibly be causing the error?
my php function
public function findCompany(){
echo "global var= ";
// var_dump($GLOBALS['headers']['Authorization']);
// var_dump($GLOBALS);
var_dump($_SERVER['REMOTE_ADDR']);
if (isset($GLOBALS['headers']['Authorization'])) {
if ($id = $this->VerifyUserToken($GLOBALS['headers']['Authorization'], $_SERVER['REMOTE_ADDR'])) {
$data = [
'company_name' => $_POST['company_name']
];
$companies = $this->currentModel->findCompany($data);
if($companies){
echo json_encode($companies);
} else {
echo json_encode(['success' => false]);
}
}
else {
echo json_encode(['success' => false, 'error' => "invalid token"]);
}
} else {
echo json_encode(['success' => false, 'error' => "token undefined"]);
}
}
}
the verifyUserToken function
public function verifyUserToken($token, $ip) {
$db = new Database();
$db->query('SELECT * FROM auth WHERE token = :token AND expiry >now()');
$db->bind(':token', $token);
//check database if token exists and is not expired
if($res = $db->single()) {
// checks if token matches to ip address
// returns user or contact id if verified else returns false
if($res->token === $token && $res->ip === $ip) {
$this->cleanTokens();
if($res->user_id >0) {
return $res->user_id;
}
//
} else {
return false;
}
} else {
return false;
}
}
I checked the database, and the token is clearly there. anyway, it's not giving me an invalid token message. it looks like the token isn't being sent.
It works fine when I do it in localhost on my machine.
IN order to debug, I used var_dump to see what gets sent. I don't have much experience with PHP, but it looks like my headers authorizations never gets set. what could be the solution
see the images and code below for what I get in the console when I try. I truncated some of the paths for security purposes
echo "global var= ";
and
var_dump($GLOBALS);
you get
["GLOBALS"]=>
*RECURSION*
["headers"]=>
array(13) {
["Host"]=>
string(20) "globalplantbased.com"
["Connection"]=>
string(10) "keep-alive"
["Content-Length"]=>
string(2) "15"
["Pragma"]=>
string(8) "no-cache"
["Cache-Control"]=>
string(8) "no-cache"
["Accept"]=>
string(33) "application/json, text/plain, */*"
["User-Agent"]=>
string(115) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"
["Content-Type"]=>
string(33) "application/x-www-form-urlencoded"
["Origin"]=>
string(27) "http://globalplantbased.com"
["Referer"]=>
string(59) "http://globalplantbased.com"
["Accept-Encoding"]=>
string(13) "gzip, deflate"
["Accept-Language"]=>
string(14) "en-US,en;q=0.9"
["Cookie"]=>
string(31) "_ga=GA1.2.1321601484.1609694939"
or
echo "global var= ";
and
var_dump($GLOBALS['headers']['Authorization']);
or
echo "global var= ";
and
var_dump($_SERVER['REMOTE_ADDR']);
[![($GLOBALS['headers']['Authorization'])2]2

$this->VerifyUserToken($GLOBALS['headers']['Authorization...
Has to be
$this->verifyUserToken($GLOBALS['headers']['Authorization
Windows does not make a Difference between capital and small Letters
Regards,
Henrik

Related

PHP Notice: Trying to get property 'status' of non-object

I am trying to get response from YTS API, however I can't understand what went wrong here. I do believe that status and status_message are objects.
Errors
PHP Notice: Trying to get property 'status' of non-object in /var/www/html/movies/inc/YTS.php on line 232
Notice: Trying to get property 'status' of non-object in /var/www/html/movies/inc/YTS.php on line 232
PHP Notice: Trying to get property 'status_message' of non-object in /var/www/html/movies/inc/YTS.php on line 233
Notice: Trying to get property 'status_message' of non-object in /var/www/html/movies/inc/YTS.php on line 233
PHP Fatal error: Uncaught Exception: API request failed. Error was: in /var/www/html/movies/inc/YTS.php:233
Code:
$url = "https://yts.mx/api/v2/list_movies.json?limit=1";
private function getFromApi($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if($e = curl_error($curl)) {
throw new Exception("Curl request failed: " . $e);
}
else {
$data = json_decode($response);
if ($data->status != 'ok') {
throw new Exception("API request failed. Error was: " . $data->status_message);
}
return $data->data;
}
curl_close($curl);
}
var_dump($data)
object(stdClass)#1 (4) { ["status"]=> string(2) "ok" ["status_message"]=> string(20) "Query was successful" ["data"]=> object(stdClass)#2 (4) { ["movie_count"]=> int(40807) ["limit"]=> int(1) ["page_number"]=> int(1) ["movies"]=> array(1) { [0]=> object(stdClass)#3 (26) { ["id"]=> int(41604) ["url"]=> string(66) "https://yts.mx/movies/a-chinese-odyssey-part-one-pandoras-box-1995" ["imdb_code"]=> string(9) "tt0112778" ["title"]=> string(41) "A Chinese Odyssey Part One: Pandora's Box" ["title_english"]=> string(41) "A Chinese Odyssey Part One: Pandora's Box" ["title_long"]=> string(48) "A Chinese Odyssey Part One: Pandora's Box (1995)" ["slug"]=> string(44) "a-chinese-odyssey-part-one-pandoras-box-1995" ["year"]=> int(1995) ["rating"]=> float(7.6) ["runtime"]=> int(87) ["genres"]=> array(3) { [0]=> string(6) "Action" [1]=> string(9) "Adventure" [2]=> string(6) "Comedy" } ["summary"]=> string(391) "Fantasy adventure about the arrival of Buddhism in China. When the Goddess of Happiness tosses the Longevity Monk and his disciples out of heaven (because the Monkey King tried to attain immortality), the Monkey King is reincarnated as the Joker. He now spends his time chasing two jealous women. When one of them is dying, the Joker goes back in time in an attempt to save her. —Anonymous" ["description_full"]=> string(391) "Fantasy adventure about the arrival of Buddhism in China. When the Goddess of Happiness tosses the Longevity Monk and his disciples out of heaven (because the Monkey King tried to attain immortality), the Monkey King is reincarnated as the Joker. He now spends his time chasing two jealous women. When one of them is dying, the Joker goes back in time in an attempt to save her. —Anonymous" ["synopsis"]=> string(391) "Fantasy adventure about the arrival of Buddhism in China. When the Goddess of Happiness tosses the Longevity Monk and his disciples out of heaven (because the Monkey King tried to attain immortality), the Monkey King is reincarnated as the Joker. He now spends his time chasing two jealous women. When one of them is dying, the Joker goes back in time in an attempt to save her. —Anonymous" ["yt_trailer_code"]=> string(11) "ZPri1X1RVeo" ["language"]=> string(2) "cn" ["mpa_rating"]=> string(0) "" ["background_image"]=> string(95) "https://yts.mx/assets/images/movies/a_chinese_odyssey_part_one_pandoras_box_1995/background.jpg" ["background_image_original"]=> string(95) "https://yts.mx/assets/images/movies/a_chinese_odyssey_part_one_pandoras_box_1995/background.jpg" ["small_cover_image"]=> string(96) "https://yts.mx/assets/images/movies/a_chinese_odyssey_part_one_pandoras_box_1995/small-cover.jpg" ["medium_cover_image"]=> string(97) "https://yts.mx/assets/images/movies/a_chinese_odyssey_part_one_pandoras_box_1995/medium-cover.jpg" ["large_cover_image"]=> string(96) "https://yts.mx/assets/images/movies/a_chinese_odyssey_part_one_pandoras_box_1995/large-cover.jpg" ["state"]=> string(2) "ok" ["torrents"]=> array(2) { [0]=> object(stdClass)#4 (10) { ["url"]=> string(72) "https://yts.mx/torrent/download/0575F561D71DD1961F01FC2CBBE22AF5598A6CF1" ["hash"]=> string(40) "0575F561D71DD1961F01FC2CBBE22AF5598A6CF1" ["quality"]=> string(4) "720p" ["type"]=> string(6) "bluray" ["seeds"]=> int(0) ["peers"]=> int(0) ["size"]=> string(9) "810.78 MB" ["size_bytes"]=> int(850164449) ["date_uploaded"]=> string(19) "2022-04-20 20:07:01" ["date_uploaded_unix"]=> int(1650478021) } [1]=> object(stdClass)#5 (10) { ["url"]=> string(72) "https://yts.mx/torrent/download/633A2CAE8DE3C9F50B2E3B89A5BC6304E4770BFE" ["hash"]=> string(40) "633A2CAE8DE3C9F50B2E3B89A5BC6304E4770BFE" ["quality"]=> string(5) "1080p" ["type"]=> string(6) "bluray" ["seeds"]=> int(0) ["peers"]=> int(0) ["size"]=> string(7) "1.63 GB" ["size_bytes"]=> int(1750199173) ["date_uploaded"]=> string(19) "2022-04-20 21:16:40" ["date_uploaded_unix"]=> int(1650482200) } } ["date_uploaded"]=> string(19) "2022-04-20 20:07:01" ["date_uploaded_unix"]=> int(1650478021) } } } ["#meta"]=> object(stdClass)#6 (4) { ["server_time"]=> int(1650488761) ["server_timezone"]=> string(3) "CET" ["api_version"]=> int(2) ["execution_time"]=> string(4) "0 ms" } } Query was successful
Code that was working using file_get_content(), but knew to fail sometimes and so I was told to use curl.
private function getFromApi($url)
{
if (!$data = file_get_contents($url)) {
$error = error_get_last();
throw new Exception("HTTP request failed. Error was: " . $error['message']);
} else {
$data = json_decode($data);
if ($data->status != 'ok') {
throw new Exception("API request failed. Error was: " . $data->status_message);
}
return $data->data;
}
}
Current code
<?php
$url = "https://yts.mx/api/v2/list_movies.json?limit=1";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if($e = curl_error($curl)) {
throw new Exception("Curl request failed: " . $e);
}
curl_close($curl);
$data = json_decode($response);
var_dump($data);
if (!$data) {
throw new Exception("JSON decode error: " . json_last_error_msg());
}
if ($data->status != 'ok') {
throw new Exception("API request failed. Error was: " . $data->status_message);
}
return $data->data;
You're probably getting an empty response, so json_decode() is failing. You need to check for this, since an empty response doesn't necessarily trigger a curl error.
private function getFromApi($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if($e = curl_error($curl)) {
throw new Exception("Curl request failed: " . $e);
}
curl_close($curl);
$data = json_decode($response);
if (!$data) {
throw new Exception("JSON decode error: " . json_last_error_msg());
}
if ($data->status != 'ok') {
throw new Exception("API request failed. Error was: " . $data->status_message);
}
return $data->data;
}
Also, there's no need to use else if the if block throws, since it never returns.

Does the Marketo REST API asset Token work?

I am following this part of the documentation: http://developers.marketo.com/rest-api/assets/tokens/ and I always get the following an error: Fields cannot be empty.
Have anyone make it worked?
public function create_token($folder_id,$name,$content,$folder_type = 'Program')
{
$folder_id = intval($folder_id);
$endpoint = 'rest/asset/v1/folder/'.$folder_id.'/tokens';
$body = new stdClass();
$body->folderType = $folder_type;
$body->name = $name;
$body->type = 'rich text';
$body->value = $content;
$body_encoded = json_encode($body);
echo $url = $this->url . $endpoint . ".json?access_token=" . self::$token;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body_encoded);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response);
}
The reason for the Content-Type header was a suggestion from Marketo: https://www.screencast.com/t/CL5ZtPo1o
This is the answer from the request I keep getting:
object(stdClass)#1934 (4) {
["success"]=>
bool(false)
["warnings"]=>
array(0) {
}
["errors"]=>
array(4) {
[0]=>
object(stdClass)#1935 (2) {
["message"]=>
string(20) "name cannot be null."
["code"]=>
string(3) "701"
}
[1]=>
object(stdClass)#1936 (2) {
["message"]=>
string(20) "type cannot be null."
["code"]=>
string(3) "701"
}
[2]=>
object(stdClass)#1937 (2) {
["message"]=>
string(101) "Token type is either null, blank or invalid. Please refer to the documentation for valid token types."
["code"]=>
string(3) "701"
}
[3]=>
object(stdClass)#1938 (2) {
["message"]=>
string(21) "value cannot be null."
["code"]=>
string(3) "701"
}
}
["requestId"]=>
string(16) "11d1#15b49284636"
}
You don't have to post token fields as JSON object: json_encode($body)
Fields are passed as request parameters or as a regular form
This request with works well for me:
POST https://123-FOO-456.mktorest.com/rest/asset/v1/folder/1039/tokens.json?value=TestTokenValue&folderType=Program&name=TestToken&type=text
In this case, you also don't have to specify content type Content-Type: x-www-form-urlencoded
I'm not PHP dev, but you can look here for examples how to post form data - PHP + curl, HTTP POST sample code?

Check if URL exists - Not Working with php get_headers

I need to determine if a URL exits. I ran across this post.
How can I check if a URL exists via PHP?
$file = 'http://godaddy';
$file_headers = #get_headers($file);
if($file_headers[0] == 'HTTP/1.1 404 Not Found')
{
$exists = false;
}
else
{
$exists = true;
}
And implemented this code and when I tested it as a user who forgot to put in the .com it comes back with true. Which isn't correct because if you go to http://godaddy there is no website.
I tried validating the $file before hand but
filter_var($url, FILTER_VALIDATE_URL);
views http://godaddy as a valid url.
Any idea how to handle this sort of input?
var_dump($file_headers)= array(8) {
[0]=> string(15) "HTTP/1.1 200 OK"
[1]=> string(13) "Server: nginx"
[2]=> string(35) "Date: Mon, 29 Jun 2015 14:23:07 GMT"
[3]=> string(23) "Content-Type: text/html"
[4]=> string(17) "Connection: close"
[5]=> string(21) "Vary: Accept-Encoding"
[6]=> string(38) "Expires: Mon, 29 Jun 2015 14:23:06 GMT"
[7]=> string(23) "Cache-Control: no-cache"
}
Try without the # character. in this way you can see the direct error. I think the error masking cannot permit the correct reading of the response of the get_header

PHP Header exists but cannot retrieve

I am using this method to make apache header request work in nginx.
if (!function_exists('apache_request_headers')) {
function apache_request_headers() {
foreach($_SERVER as $key=>$value) {
if (substr($key,0,5)=="HTTP_") {
$key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
$out[$key]=$value;
}else{
$out[$key]=$value;
}
}
return $out;
}
}
I retrieve the header like so $headers = apache_request_headers(); and use an array to hold json.
$response=array()
$response["error"] = true;
$response["message"] = $headers;
The code below is what is inside of the $response array variable:
{
error: true
message: {
CONTENT_LENGTH: "13"
CONTENT_TYPE: "application/x-www-form-urlencoded"
DOCUMENT_ROOT: "/home4/admin/public_html"
GATEWAY_INTERFACE: "CGI/1.1"
Accept: "*/*"
Accept-Encoding: "gzip, deflate"
Accept-Language: "en-US,en;q=0.8"
Connection: "close"
Cookie: "_ga=GA1.2.1266385826.1428275832"
Host: "mysite.com"
Origin: "chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo"
User-Agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36"
X-Apikey: "bca0de3e7c10cb6623ef00021caf9450"
X-Http-Proto: "HTTP/1.1"
X-Log-7528: "107.147.160.193"
X-Real-Ip: "107.147.160.193"
PATH: "/bin:/usr/bin"
PHPRC: "/home4/admin"
QUERY_STRING: ""
REDIRECT_STATUS: "200"
REDIRECT_UNIQUE_ID: "VVlk5sD##rgAACwVT0AAAACM"
REDIRECT_URL: "/rmapp/v1/tasks"
REMOTE_ADDR: "107.147.160.193"
REMOTE_PORT: "31527"
REQUEST_METHOD: "POST"
REQUEST_URI: "/rmapp/v1/tasks"
SCRIPT_FILENAME: "/home4/admin/public_html/rmapp/v1/index.php"
SCRIPT_NAME: "/rmapp/v1/index.php"
SERVER_ADDR: "192.185.226.161"
SERVER_ADMIN: "webmaster#mysite.com"
SERVER_NAME: "mysite.com"
SERVER_PORT: "80"
SERVER_PROTOCOL: "HTTP/1.1"
SERVER_SIGNATURE: "<address>Apache Server at mysite.com Port 80</address> "
SERVER_SOFTWARE: "Apache"
UNIQUE_ID: "VVlk5sD##rgAACwVT0AAAACM"
PHP_SELF: "/rmapp/v1/index.php"
REQUEST_TIME: 1431921894
argv: [0]
argc: 0
}-
}
My problem is, I need to grab X-ApiKey from $header, but using $api_key = $headers['X-ApiKey']; returns nothing, but as you can see, X-ApiKey exists in $header. Can someone please tell me what I'm missing here?
Looks like you are using the wrong variable name. Variable names are case-sensitive.
The response returns the following (small k in Apikey):
X-Apikey: "bca0de3e7c10cb6623ef00021caf9450"
while you are using capital k $api_key = $headers['X-ApiKey'];
Try the following:
$api_key = $headers['X-Apikey'];
$response["message"] is a string. First try to explode it and then access it -
$temp = explode('X-Apikey:', $response['message']);
$temp1 = explode('X-Http-Proto:', $temp[1]);
var_dump(trim(str_replace('"', '', $temp1[0])));
Output
string(32) "bca0de3e7c10cb6623ef00021caf9450"

LinkedIn API returns 'Unauthorized' response (PHP OAuth)

I've been struggling with this one for a few days now. I've got a test app set up to connect to LinkedIn via OAuth. I want to be able to update a user's status, but at the moment I'm unable to interact with LinkedIn's API at all.
I am able to successfully get a requestToken, then an accessToken, but when I issue a request to the API, I see an 'unauthorized' error that looks something like this:
object(OAuthException)#2 (8) {
["message:protected"]=> string(73) "Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)"
["string:private"]=> string(0) ""
["code:protected"]=> int(401)
["file:protected"]=> string(47) "/home/pmfeorg/public_html/dev/test/linkedin.php"
["line:protected"]=> int(48)
["trace:private"]=> array(1) {
[0]=> array(6) {
["file"]=> string(47) "/home/pmfeorg/public_html/dev/test/linkedin.php"
["line"]=> int(48)
["function"]=> string(5) "fetch"
["class"]=> string(5) "OAuth"
["type"]=> string(2) "->"
["args"]=> array(2) {
[0]=> string(35) "http://api.linkedin.com/v1/people/~"
[1]=> string(3) "GET"
}
}
}
["lastResponse"]=> string(358) " 401 1276375790558 0000 [unauthorized]. OAU:Bhgk3fB4cs9t4oatSdv538tD2X68-1OTCBg-KKL3pFBnGgOEhJZhFOf1n9KtHMMy|48032b2d-bc8c-4744-bb84-4eab53578c11|*01|*01:1276375790:xmc3lWhXJvLSUZh4dxMtrf55VVQ= "
["debugInfo"]=> array(5) {
["sbs"]=> string(329) "GET&http%3A%2F%2Fapi.linkedin.com%2Fv1%2Fpeople%2F~&oauth_consumer_key%3DBhgk3fB4cs9t4oatSdv538tD2X68-1OTCBg-KKL3pFBnGgOEhJZhFOf1n9KtHMMy%26oauth_nonce%3D7068001084c13f2ee6a2117.22312548%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1276375790%26oauth_token%3D48032b2d-bc8c-4744-bb84-4eab53578c11%26oauth_version%3D1.0"
["headers_sent"]=> string(401) "GET /v1/people/~?GET&oauth_consumer_key=Bhgk3fB4cs9t4oatSdv538tD2X68-1OTCBg-KKL3pFBnGgOEhJZhFOf1n9KtHMMy&oauth_signature_method=HMAC-SHA1&oauth_nonce=7068001084c13f2ee6a2117.22312548&oauth_timestamp=1276375790&oauth_version=1.0&oauth_token=48032b2d-bc8c-4744-bb84-4eab53578c11&oauth_signature=xmc3lWhXJvLSUZh4dxMtrf55VVQ%3D HTTP/1.1 User-Agent: PECL-OAuth/1.0-dev Host: api.linkedin.com Accept: */*"
["headers_recv"]=> string(148) "HTTP/1.1 401 Unauthorized Server: Apache-Coyote/1.1 Date: Sat, 12 Jun 2010 20:49:50 GMT Content-Type: text/xml;charset=UTF-8 Content-Length: 358"
["body_recv"]=> string(358) " 401 1276375790558 0000 [unauthorized]. OAU:Bhgk3fB4cs9t4oatSdv538tD2X68-1OTCBg-KKL3pFBnGgOEhJZhFOf1n9KtHMMy|48032b2d-bc8c-4744-bb84-4eab53578c11|*01|*01:1276375790:xmc3lWhXJvLSUZh4dxMtrf55VVQ= "
["info"]=> string(216) "About to connect() to api.linkedin.com port 80 (#0) Trying 64.74.98.83... connected Connected to api.linkedin.com (64.74.98.83) port 80 (#0) Connection #0 to host api.linkedin.com left intact Closing connection #0 "
}
}
My code looks like this (based on the FireEagle example from php.net):
$req_url = 'https://api.linkedin.com/uas/oauth/requestToken';
$authurl = 'https://www.linkedin.com/uas/oauth/authenticate';
$acc_url = 'https://api.linkedin.com/uas/oauth/accessToken';
$api_url = 'http://api.linkedin.com/v1/people/~';
$callback = 'http://www.pmfe.org/dev/test/linkedin.php';
$conskey = 'Bhgk3fB4cs9t4oatSdv538tD2X68-1OTCBg-KKL3pFBnGgOEhJZhFOf1n9KtHMMy';
$conssec = '####################SECRET KEY#####################';
session_start();
try {
$oauth = new OAuth($conskey,$conssec,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
if(!isset($_GET['oauth_token'])) {
$request_token_info = $oauth->getRequestToken($req_url);
$_SESSION['secret'] = $request_token_info['oauth_token_secret'];
header('Location: '.$authurl.'?oauth_token='.$request_token_info['oauth_token']);
exit;
} else {
$oauth->setToken($_GET['oauth_token'],$_SESSION['secret']);
$access_token_info = $oauth->getAccessToken($acc_url);
$_SESSION['token'] = $access_token_info['oauth_token'];
$_SESSION['secret'] = $access_token_info['oauth_token_secret'];
}
$oauth->setToken($_SESSION['token'],$_SESSION['secret']);
$oauth->fetch($api_url, OAUTH_HTTP_METHOD_GET);
$response = $oauth->getLastResponse();
} catch(OAuthException $E) {
var_dump($E);
}
I've successfully set up a connection to Twitter and one to Facebook using OAuth, but LinkedIn keeps eluding me. If anyone could offer some advice or point me in the right direction, I will be extremely appreciative!
Well, I found the source of the problem, but there's a new problem now:
My original question was wrong - I wasn't getting an accessToken at all. The problem was that I wasn't passing the verifier code (obtained during the requestToken step) during the getAccessToken call.
So rather than this...
$access_token_info = $oauth->getAccessToken($acc_url);
...I needed to do this...
$_SESSION['verifier'] = $_GET['oauth_verifier'];
$access_token_info = $oauth->getAccessToken($acc_url, $_SESSION['verifier'], $_SESSION['verifier']);
I hope this info helps someone else out. This is the first time I've worked with OAuth, but it seems like LinkedIn has a very strict implementation.
Anyway, now I need to figure out why LI is returning a 401 when I try to update my status... I've authorized the app, and can pull data down, but am unable to set any data. Maybe there are additional permissions hidden in LI's settings somewhere?
Unless LinkedIn has a totally wonky view of HTTP status codes, 401 means it was expecting a WWW-Authenticate header (ie: username/password in base64 format) and didn't get it, so it's denying access.
Perhaps you have to do an OAuth::setAuthType().

Categories