Need some help with Code Auth

Here’s my PHP code. I can only seem to get a NULL return and a 400 response. I can’t seem to get it to come in right. I feel like I’ve checked everything 100 times and it’s just not coming. I know the clientID and secret are right. I would appreciate any help. (PS. Iv’e tried to get into a slack that was recommended for fuzzyworks but not getting the invite after a few attempts.)

	$codeReturn = ($_GET["code"]);
	$url = 'https://login.eveonline.com/oauth/token HTTP/1.1';
	
	$sql = "SELECT * FROM `auth_AppConfig` LIMIT 1";
	$resultSql = $connection->query($sql);
	$clientData = $resultSql->fetch_assoc();
	$connection->close();
	
	$clientID = $clientData["auth_AppConfig_clientID"];
	$clientSecret = $clientData["auth_AppConfig_clientSecret"];
	$baseEncodeClient = 'Basic '.base64_encode($clientID.":".$clientSecret);
	$headers = "Authorization: ".$baseEncodeClient."\r\nContent-Type: application/x-www-form-urlencoded\r\nHost: login.eveonline.com";
	$fields = http_build_query(array('grant_type' => 'authorization_code', 'code' => $codeReturn));

	$ch = curl_init();

	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, $headers);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	
	$result = curl_exec($ch);

	var_dump(json_decode($result));

See example below:

I’ll give this a shot. Was concerned because of this on the doc page:

Alternatively, while not in accordance with the OAuth 2.0 standard, the body of the request may use JSON encoding.

See example below:

Returned back an empty page.

when i put in the following, it was NULL

var_dump($response);

Oops, my bad, the URL for those should be https://login.eveonline.com/oauth/token i was setup using the JWT beta endpoints.

Full Example, tested and working as of PHP 7.0.30

<?php

$curl = curl_init();
$clientId = "";
$clientSecret = "";
$code = "";

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://login.eveonline.com/oauth/token",
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "grant_type=authorization_code&code=".$code,
  CURLOPT_HTTPHEADER => array(
    "authorization: Basic " . base64_encode($clientId . ":" . $clientSecret),
    "content-type: application/x-www-form-urlencoded"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

var_dump($response);
var_dump($err);

OK, now I"m seeing bool(true) response now.

I think I can move on from here.

Thanks for now!

OK, so now no matter what I do I’m only seeing

“bool(true)”

If I try to get json_decode it, it goes to “1”. What am I missing…

Sounds like you’re not actually getting the body of the response, but just if it was successful or not.

The code i posted above was working and was seeing the output. Compare what you got with that. Also what PHP version you on?

Try adding curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); to your curl setup.

So I’ve narrowed it down to the fact that if I hard code the client ID and secret, the POST passes. If I pull it from a database, it fails…

I appreciate all the help.

Gotcha, sounds like an easy fix. Just make sure what is coming back from db is what you are expecting?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.