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

The new forums are live and can be found at

EVE Technology Lab

  • Topic is locked indefinitely.

[PHP] SSO retrieve the token

Lucie Tokila
Dialkyl Peroxides
#1 - 2017-06-13 19:37:08 UTC  |  Edited by: Lucie Tokila

I am using the old API for a long time now I need to use SSO and ESI.

To use SSO I am developing a Web App and I need help for the retrieve token part.

I have a problem with this following method the Post Request step (the php go in this method with I receive the code from CCP and this method print the token)

function retrieveToken()
    $header = 'Authorization: Basic ' . base64_encode($_SESSION['clientid'] . ':' . $_SESSION['clientsecret']);
    $fields_string = '';
    $fields = array(
        'grant_type' => 'authorization_code',
        'code' => $_GET['code']
    foreach ($fields as $key => $value) {
        $fields_string .= $key . '=' . $value . '&';
    rtrim($fields_string, '&');
    // Build Http query using params
    $query = http_build_query ($fields);
    // Create Http context details
    $contextData = array (
                    'method' => 'POST',
                    'header' => "Connection: close\r\n".
                                "Content-Length: ".strlen($query)."\r\n",
                    'content'=> $query );
    // Create context resource for our request
    $context = stream_context_create (array ( 'https' => $contextData ));

    // Read page rendered as result of your POST request
    $result =  file_get_contents (
                      '',  // page url
     echo $result;

with this error : file_get_contents( failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

any ideas ? :)
(you can correct me because I know that I writed something wrong :/)
Althalus Stenory
Flying Blacksmiths
#2 - 2017-06-14 10:03:47 UTC
    $contextData = array ( 
                    'method' => 'POST',
                    'header'  => "Content-type: application/x-www-form-urlencoded\r\n" . $header . "\r\n",
                    'content'=> $query );

This "might be" enough. (You were mostly missing your auth header and also content-type)

After, if you get a 404, it seems that you don't still do POST request but GET (login/oauth/token return 404 on GET, 400 on POST without parameters).

If you can't get it to work, a solution can be to use CURL instead of file_get_contents

EsiPy - Python 2.7 / 3.3+ Swagger Client based on pyswagger for ESI

Lucie Tokila
Dialkyl Peroxides
#3 - 2017-06-14 16:01:11 UTC
Thx for your repply, I tryed with Post and Get = same problem.

I delete everything and I will try with the oauth2-eveonline package.

Maybe the easy way is better for my php skills

best regard
Minerva Arbosa
Spatial Forces
Warped Intentions
#4 - 2017-06-14 18:25:33 UTC
Just use curl.