1

Trying my hand at using the new Eve ESI interface but am receiving the following error response when trying to authenticate:

HTTP/1.1 401 Unauthorized
Cache-Control: private
Server: Microsoft-IIS/8.5
Request-Context: appId=cid-v1:2ccf88f2-29b9-460a-bc15-7c0b79926f61
Date: Tue, 01 May 2018 00:24:50 GMT
Connection: close
Content-Length: 0

Here is my code, using PHP/Curl:

<?php   
    $authcode = base64_encode("{my client ID}:{My Secret Key}");
    $data = array("grant_type" => "authorization_code", "code" => "{code returned by the server}");
    $data_string = json_encode($data);
    $ch = curl_init("https://login.eveonline.com/oauth/token");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HEADER, array("Content-Type:application/json", "Authorization: Basic " . $authcode)); 

    $result = curl_exec($ch); 

    print_r($result);

    curl_close($ch); 
?> 

Any ideas what I'm doing wrong? I've been following the user guide as closely as I can figure.

Thanks.

robsiemb
  • 6,157
  • 7
  • 32
  • 46
tllewellyn
  • 903
  • 2
  • 7
  • 28
  • Do they provide a dev test api? If so try it first with the given username and pw, else check if your passed username and pw are correct as it gives unauthorized, also you are giving the response header where is the body? Mostly the body will be in json format and contains some info – xYuri May 02 '18 at 17:44
  • Also if u want to keep the login session you need to set `COOKIESESSION` `COOKIEJAR` `COOKIEFILE` i can submit an example in an answer if you want. – xYuri May 02 '18 at 17:53

1 Answers1

0

Try this:

    //Request Headers payload
    $headerData = array(
        "Authorization:Basic " . base64_encode("{my client ID}:{My Secret Key}"),
        "Content-Type:application/json", 
        'Host:login.eveonline.com'
    )

    //Request Body payload
    $bodyData = array(
        "grant_type" => "authorization_code", 
        "code" => "{code returned by the server}"
    );

    //Curl exec
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://login.eveonline.com/oauth/token");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headerData); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($bodyData)); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $result = curl_exec($ch); 
    curl_close($ch); 

    //Server response json decode & display
    $result = json_decode($result, true);
    print_r($result);
Shtimpok
  • 1
  • 3