# Need some help with Code Auth

**URL:** <https://forums.eveonline.com/t/need-some-help-with-code-auth/104738>\
**Category:** Third Party Developers\
**Created:** [September 8, 2018, 12:19am UTC](https://forums.eveonline.com/t/need-some-help-with-code-auth/104738 "2018-09-08T00:19:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Higive\_Ghudhed](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/higive_ghudhed/32/40691_2.png) [@Higive\_Ghudhed](https://forums.eveonline.com/u/Higive_Ghudhed)\
**Post date:** [September 8, 2018, 12:19am UTC](https://forums.eveonline.com/t/need-some-help-with-code-auth/104738/1 "2018-09-08T00:19:53Z")

</div>

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));
```

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/blacksmoke16/32/376589_2.png) [@Blacksmoke16](https://forums.eveonline.com/u/Blacksmoke16)\
**Post date:** [September 8, 2018, 12:27am UTC](https://forums.eveonline.com/t/need-some-help-with-code-auth/104738/2 "2018-09-08T00:27:19Z")

</div>

See example below:

---

<div class="post-metadata">

**Author:** ![Higive\_Ghudhed](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/higive_ghudhed/32/40691_2.png) [@Higive\_Ghudhed](https://forums.eveonline.com/u/Higive_Ghudhed)\
**Post date:** [September 8, 2018, 12:32am UTC](https://forums.eveonline.com/t/need-some-help-with-code-auth/104738/3 "2018-09-08T00:32:38Z")

</div>

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.
```

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/blacksmoke16/32/376589_2.png) [@Blacksmoke16](https://forums.eveonline.com/u/Blacksmoke16)\
**Post date:** [September 8, 2018, 12:38am UTC](https://forums.eveonline.com/t/need-some-help-with-code-auth/104738/5 "2018-09-08T00:38:45Z")

</div>

See example below:

---

<div class="post-metadata">

**Author:** ![Higive\_Ghudhed](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/higive_ghudhed/32/40691_2.png) [@Higive\_Ghudhed](https://forums.eveonline.com/u/Higive_Ghudhed)\
**Post date:** [September 8, 2018, 12:47am UTC](https://forums.eveonline.com/t/need-some-help-with-code-auth/104738/6 "2018-09-08T00:47:23Z")

</div>

Returned back an empty page.

when i put in the following, it was NULL

var\_dump($response);

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/blacksmoke16/32/376589_2.png) [@Blacksmoke16](https://forums.eveonline.com/u/Blacksmoke16)\
**Post date:** [September 8, 2018, 1:05am UTC](https://forums.eveonline.com/t/need-some-help-with-code-auth/104738/7 "2018-09-08T01:05:47Z")

</div>

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`

```auto
<?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);
```

---

<div class="post-metadata">

**Author:** ![Higive\_Ghudhed](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/higive_ghudhed/32/40691_2.png) [@Higive\_Ghudhed](https://forums.eveonline.com/u/Higive_Ghudhed)\
**Post date:** [September 8, 2018, 1:13am UTC](https://forums.eveonline.com/t/need-some-help-with-code-auth/104738/8 "2018-09-08T01:13:31Z")

</div>

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

I think I can move on from here.

Thanks for now!

---

<div class="post-metadata">

**Author:** ![Higive\_Ghudhed](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/higive_ghudhed/32/40691_2.png) [@Higive\_Ghudhed](https://forums.eveonline.com/u/Higive_Ghudhed)\
**Post date:** [September 8, 2018, 2:54am UTC](https://forums.eveonline.com/t/need-some-help-with-code-auth/104738/9 "2018-09-08T02:54:31Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/blacksmoke16/32/376589_2.png) [@Blacksmoke16](https://forums.eveonline.com/u/Blacksmoke16)\
**Post date:** [September 8, 2018, 3:42am UTC](https://forums.eveonline.com/t/need-some-help-with-code-auth/104738/10 "2018-09-08T03:42:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Higive\_Ghudhed](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/higive_ghudhed/32/40691_2.png) [@Higive\_Ghudhed](https://forums.eveonline.com/u/Higive_Ghudhed)\
**Post date:** [September 8, 2018, 4:16am UTC](https://forums.eveonline.com/t/need-some-help-with-code-auth/104738/11 "2018-09-08T04:16:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/blacksmoke16/32/376589_2.png) [@Blacksmoke16](https://forums.eveonline.com/u/Blacksmoke16)\
**Post date:** [September 8, 2018, 4:22am UTC](https://forums.eveonline.com/t/need-some-help-with-code-auth/104738/12 "2018-09-08T04:22:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/eveonline/original/3X/4/1/41ec4921cbaca7a6f9ea556e7cc20018461eae5e.png) [@system](https://forums.eveonline.com/u/system)\
**Post date:** [December 7, 2018, 4:22am UTC](https://forums.eveonline.com/t/need-some-help-with-code-auth/104738/13 "2018-12-07T04:22:48Z")

</div>

Closed on December 7, 2018, 4:22am UTC

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