Morigan Macha
Zebra Corp Goonswarm Federation
0
|
Posted - 2016.05.24 16:47:53 -
[1] - Quote
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
4311
|
Posted - 2016.05.24 16:50:36 -
[2] - Quote
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
Zebra Corp Goonswarm Federation
0
|
Posted - 2016.05.25 01:56:43 -
[4] - Quote
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);
|