# Help needed (PHP / request / access token etc. (SOLVED)

**URL:** <https://forums.eveonline.com/t/help-needed-php-request-access-token-etc-solved/392592>\
**Category:** Third Party Developers\
**Tags:** api, esi\
**Created:** [January 20, 2023, 6:50pm UTC](https://forums.eveonline.com/t/help-needed-php-request-access-token-etc-solved/392592 "2023-01-20T18:50:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vico\_Castiglione](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/vico_castiglione/32/351108_2.png) [@Vico\_Castiglione](https://forums.eveonline.com/u/Vico_Castiglione)\
**Post date:** [January 20, 2023, 6:50pm UTC](https://forums.eveonline.com/t/help-needed-php-request-access-token-etc-solved/392592/1 "2023-01-20T18:50:00Z")

</div>

I created a login button on my website to requests an authenication code from the EVE SSO.  
After I received this authentication code I need to send a POST request, for an access token.  
Does anyone have an example for me of how I can do this with PHP?

---

<div class="post-metadata">

**Author:** ![Tonto\_Auri](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/tonto_auri/32/388339_2.png) [@Tonto\_Auri](https://forums.eveonline.com/u/Tonto_Auri)\
**Post date:** [January 21, 2023, 12:11pm UTC](https://forums.eveonline.com/t/help-needed-php-request-access-token-etc-solved/392592/2 "2023-01-21T12:11:42Z")

</div>

There’s tons of examples. What exactly is your issue?

---

<div class="post-metadata">

**Author:** ![Vico\_Castiglione](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/vico_castiglione/32/351108_2.png) [@Vico\_Castiglione](https://forums.eveonline.com/u/Vico_Castiglione)\
**Post date:** [January 21, 2023, 9:33pm UTC](https://forums.eveonline.com/t/help-needed-php-request-access-token-etc-solved/392592/3 "2023-01-21T21:33:33Z")

</div>

Hi, thank you for your reply. I will try to explain more…

---

<div class="post-metadata">

**Author:** ![Vico\_Castiglione](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/vico_castiglione/32/351108_2.png) [@Vico\_Castiglione](https://forums.eveonline.com/u/Vico_Castiglione)\
**Post date:** [January 21, 2023, 9:42pm UTC](https://forums.eveonline.com/t/help-needed-php-request-access-token-etc-solved/392592/4 "2023-01-21T21:42:45Z")

</div>

I followed the information on this page:  
[https://docs.esi.evetech.net/docs/sso/web\_based\_sso\_flow.html](https://docs.esi.evetech.net/docs/sso/web_based_sso_flow.html)

I managed to handle the steps 1 to 4 on that page, so now my own login page (PHP-file) receives an authentication code with a state that I can further process to request an access token from the EVE SSO. All is good here.  
Next I need to send a POST request so I can receive an access token. (Step 5 on the linked page.) I have a hard time translating the given information into working PHP-code. That is why I’m asking if anybody here has an example for me.

---

<div class="post-metadata">

**Author:** ![Vico\_Castiglione](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/vico_castiglione/32/351108_2.png) [@Vico\_Castiglione](https://forums.eveonline.com/u/Vico_Castiglione)\
**Post date:** [January 21, 2023, 10:12pm UTC](https://forums.eveonline.com/t/help-needed-php-request-access-token-etc-solved/392592/5 "2023-01-21T22:12:11Z")

</div>

I tried this:

```auto
$the_request_url = "https://login.eveonline.com/v2/oauth/token";
$the_request_postfields = array(	'grant_type' => 'authorization_code',
									'code' => $received_code );
$the_request_headers = array(	'Authorization' => 'Basic ' . base64_encode( $EVE_Application_ClientID . ":" . $EVE_Application_SecretKey),
									'Content-Type' => 'application/x-www-form-urlencoded',
									'Host' => 'login.eveonline.com' );

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $the_request_url);
curl_setopt($h_curl, CURLOPT_POST, 1);
curl_setopt($h_curl, CURLOPT_POSTFIELDS, http_build_query($the_request_postfields));
curl_setopt($h_curl, CURLOPT_HTTPHEADER, $the_request_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$resp = curl_exec($ch);

if($e = curl_error($ch)) {
	echo $e;
}
else {
	var_dump($resp);
}

curl_close($ch);

```

The curl\_error() function did not respond with an error and the $resp variable is empty.

---

<div class="post-metadata">

**Author:** ![Vico\_Castiglione](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/vico_castiglione/32/351108_2.png) [@Vico\_Castiglione](https://forums.eveonline.com/u/Vico_Castiglione)\
**Post date:** [January 22, 2023, 12:44am UTC](https://forums.eveonline.com/t/help-needed-php-request-access-token-etc-solved/392592/6 "2023-01-22T00:44:25Z")

</div>

A `curl_getinfo()` after the `curl_exec()` function returned `[http_code] => 405`.  
This looks like a hint. Any help is appreciated. 🙂

---

<div class="post-metadata">

**Author:** ![Vico\_Castiglione](https://sea1.discourse-cdn.com/eveonline/user_avatar/forums.eveonline.com/vico_castiglione/32/351108_2.png) [@Vico\_Castiglione](https://forums.eveonline.com/u/Vico_Castiglione)\
**Post date:** [January 22, 2023, 6:50pm UTC](https://forums.eveonline.com/t/help-needed-php-request-access-token-etc-solved/392592/7 "2023-01-22T18:50:09Z")

</div>

I found a video with a good example. Thank you @pengo1998. 👍🏻

[![](https://global.discourse-cdn.com/eveonline/original/4X/3/b/4/3b4b0a6ffb95fc7a6c97666fa78fe54c49875b02.jpeg "(PHP) EVE Online SSO/ESI | Episode 2 - Using The SSO service") ](https://www.youtube.com/watch?v=dRTeqo5U7jw)

---

<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:** [April 22, 2023, 6:50pm UTC](https://forums.eveonline.com/t/help-needed-php-request-access-token-etc-solved/392592/8 "2023-04-22T18:50:30Z")

</div>

Closed on April 22, 2023, 6:50pm UTC

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