These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

SSO - How to get the access_code with a php curl

First post
Author
Vex Munda
Anti Enslavement Movement
#1 - 2016-12-27 15:32:25 UTC
Hey,

I am trying to 'Verify the authorization code' in the SSO process done in a php file using curl. The php receives the authorization code provided earlier in the page url. And it should return an access_code. But at the moment I am getting the following error from the eve server: {"error":"invalid_request","error_description":"Unknown grant_type"}

Any idea what I did wrong here? Is it something to do with the CURLOPT_POSTFIELDS?

$authorization_code =  $_REQUEST["code"];
$url = "https://login.eveonline.com/oauth/token";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); // required as of PHP 5.6.0
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode('grant_type=authorization_code&
    code='.$authorization_code));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization: Basic RVByaEI2Y2xMV2xWdkhydQ==',
    'Content-type: application/x-www-form-urlencoded',
    'Host: login.eveonline.com'
    ));
$result = curl_exec($ch);
if($result === false){
    echo "curl error: " . curl_error($ch);
    echo $result;
}
else{
    echo "succes: ";
    echo $result;
}
curl_close($ch);
Steve Ronuken
Fuzzwork Enterprises
Vote Steve Ronuken for CSM
#2 - 2016-12-27 20:01:47 UTC
https://github.com/fuzzysteve/eve-sso-auth/blob/master/devauthcallback.php may be of interest.

I'm not _entirely_ sure, but I suspect it's the urlencode of the & which is screwing it up.

So it's encoding the &, which means you have grant_type being "authorization_code&code=lsfkjdlsnfeklskejflskenlekfsh" rather than the & being literal and acting as a field break

Woo! CSM XI!

Fuzzwork Enterprises

Twitter: @fuzzysteve on Twitter

David Davaham
Deep Blue Logistics
#3 - 2016-12-27 20:55:33 UTC  |  Edited by: David Davaham
I recommend this PHP Curl Class from Github.

I am using it on my current project and it is working wonders, and it gives me a shite tone of information back to assist me in debugging situations. I HIGHLY recommend you look into this and implement it in your project. I have included what the call in your code would look like using this class.

EVE Online Forums are gay when it comes to posting code so click this link to see my example


Link to GitHub Repo

Developer of EVEmail

Steve Ronuken
Fuzzwork Enterprises
Vote Steve Ronuken for CSM
#4 - 2016-12-27 21:00:17 UTC
I actually recommend using Guzzle, rather than directly using Curl. http://docs.guzzlephp.org/en/latest/

works well Smile

Woo! CSM XI!

Fuzzwork Enterprises

Twitter: @fuzzysteve on Twitter