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.
 

CREST Response with http_code 400 | invalide_request

First post
Author
Morigan Macha
Imperial Academy
Amarr Empire
#1 - 2016-05-24 16:47:53 UTC
I've got a problem with retriving a refreshToken from CREST, basicly it does not find the Code on the CREST Server, this is the bit of Code i use to send the Code and to recive the refreshToken

    
    public function retrieveRefreshToken()
    {
        
        if ($this->getLoginState() != 3) {
            throw new Exception('Trying to Retrieve a Refreshment Token with a wrong Login state');
            return null;
        }
            
        $header = 'Authorization: Basic ' . $this->cfg->getBase64AuthString(); // { return base64_encode($this->m_clientId . ':' . $this->m_secretKey); }
        $fields_string = '';
        $fields = array(
                'grant_type' => 'authorization_code',
                'code' => $_GET['code'],
        );

        
        foreach ($fields as $key => $value) {
            $fields_string .= $key . '=' . $value . '&';
        }
        rtrim($fields_string, '&');
        
        $ch = curl_init();
        
        curl_setopt_array(
                $ch,
                array(
                        CURLOPT_URL             => $this->cfg->getCrestTokenUrl(),
                        CURLOPT_POST            => true,
                        CURLOPT_POSTFIELDS      => $fields_string,
                        CURLOPT_HTTPHEADER      => array($header),
                        CURLOPT_RETURNTRANSFER  => true,
                        CURLOPT_USERAGENT       => $this->cfg->getUserAgent(),
                        CURLOPT_SSL_VERIFYPEER  => true,
                        CURLOPT_SSL_CIPHER_LIST => 'TLSv1', //prevent protocol negotiation fail
                )
                );

        $rPage = new CrestRequestPage();
        
        $rPage->errorNumber = curl_errno($ch);
        $rPage->errorMsg = curl_error($ch);
        $rPage->contentJsonDecoded = json_decode(curl_exec($ch));
        $rPage->content = curl_exec($ch);
        $rPage->header = curl_getinfo($ch);
        
        curl_close($ch);
        
        if ($rPage->errorNumber != 0)
            throw new Exception($rPage->errorMsg, $rPage->errorNumber);
        if (!in_array($rPage->header['http_code'], array(200, 302)))
            throw new Exception(
                    'HTTP response not OK: ' . (int) $rPage->header['http_code'] . '. Response body: ' . $rPage->content,
                    $rPage->header['http_code']
                    );
                
        
        $_SESSION['refreshToken'] = $rPage->contentJsonDecoded->refresh_token;
    }


this is the content i get from CREST, basicly the error:

    [content] => {"error":"invalid_request","error_description":"Authorization code not found"}


I really dont know why it does not find the related code, because i get it directly after CREST is redirecting back to me, maybe someone finds the problem i have
CCP FoxFour
C C P
C C P Alliance
#2 - 2016-05-24 16:50:36 UTC
What URL are you sending this request to?

@CCP_FoxFour // Technical Designer // Team Tech Co

Third-party developer? Check out the official developers site for dev blogs, resources, and more.

Morigan Macha
Imperial Academy
Amarr Empire
#3 - 2016-05-24 16:53:12 UTC
$this->cfg->getCrestTokenUrl() == "https://login.eveonline.com/oauth/token"
Morigan Macha
Imperial Academy
Amarr Empire
#4 - 2016-05-25 01:56:43 UTC
after tingling around i found my error:

        $rPage->contentJsonDecoded = json_decode(curl_exec($ch));
        $rPage->content = curl_exec($ch);


this part is my problem, i got the refresh token, and decoded it into my "contentJsonDecoded", but then i called the page again and got the error that the token is not valid (because its just a one use token, i fixed it with:


        $rPage->content = curl_exec($ch);
        $rPage->contentJsonDecoded = json_decode($rPage->content);