0

I try to create a register function with linkedIn in my website.

As you know, linkedIn has 2 step authentication to get Access token.

See StackOverflow answer here : Click here

From the thread above, i try to do the second step with PHP cUrl.

$url = "https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code&code=" . $_GET['code'] . "&redirect_uri=A_URL&client_id=MY_CLIENT_ID&client_secret=SECRET";
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL            => $url,
  CURLOPT_SSL_VERIFYPEER => false,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST  => "POST",
  CURLOPT_TIMEOUT        => 1000,
  CURLOPT_HTTPHEADER     => array(
    "Content-Length: 1000" 
  )
));

$response = curl_exec($curl);
$err      = curl_error($curl);

curl_close($curl);

if (!$err) {
  $response = json_decode($response);
} else {
  throw new exception(__METHOD__ . '() ' . $err . ', on line : ' . __LINE__);
}

but when the curl_exec() is executed, the page goes to loading infinitely.

I do not know what's my mistake. I try to run the $url manually via the url box, it return a token and expired time successfully. So, i conclude the mistake is in the cUrl.

Any help guys ?,

Thank you very much.

5
  • Before you start do go any further read this:oauth.net/2 Commented May 26, 2017 at 7:37
  • That 2 step verification is called oauth,you are now making a client. Commented May 26, 2017 at 7:38
  • Here is Googles Play Ground for OAuth developers.google.com/oauthplayground Commented May 26, 2017 at 7:38
  • You can test it out to see how OAuth works and when are tokens taken.And here is a simple kick start for you github.com/thephpleague/oauth2-client Commented May 26, 2017 at 7:40
  • It's more complex than that one POST statement :D Commented May 26, 2017 at 7:40

1 Answer 1

1

CURLOPT_CUSTOMREQUEST => "GET"

and delete CURLOPT_HTTPHEADER option, It's useless.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't really understand what happen, but it works. ~
don't use CUSTOMREQUEST for GET and POST requests, use CURLOPT_HTTPGET or CURLOPT_POST

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.