I’m trying to write an application on a LAMP stack. I’ve made SSO work before, but I seem to just not understand exactly what the f is going on.
I’m trying to write in php. Let me explain the concepts I think I understand and please correct me where I am wrong.
Setting up the application at the developer site and building the link to the login page is simple enough. I have an HTML page with:
<html>
<body>
<a href="https://login.eveonline.com/oauth/authorize?response_type=code&redirect_uri=https://mysite.com/myApp/myCallback.php&client_id=MY_APP_ID&scope=publicData%20esi-killmails.read_killmails.v1">Log in with Eve Online</a>
</body>
</html>
EZ
The user is directed to login at CCP’s website and if successful my callback url is called with a GET value of code=??
That URL looks like:
https://mysite.com/myCallback.php?code=SOME_CODE
As I understand it, this gives me an almost useless one time use authorization code. The only thing this is good for is retrieving 2 more codes that the API could have just given me when the user authenticated.
Whatever.
I try to use this key to get an Access Token and a Refresh Token.
<?php
//there should be a get field with $code in it. The code in this URL is a one-use-only authorization code that can be exchanged with the SSO for an Access token and a refresh token.
$code = $_GET['code'] ;
//Headers payload
$headerData = array(
//Client ID and Secret Key should be environment variables.
//They are hardcoded here to rule out issues with incorrect values
"Authorization:Basic " . base64_encode("HARD_CODED_CLIENT_ID:HARD_CODED_SECRET_KEY"),
"Content-Type:application/json",
'Host:login.eveonline.com'
);
//Body payload
$bodyData = array(
"grant_type" => "authorization_code",
"code" => $code ,
);
//We have built out the request and now we just need to execute it.
//Curl exec
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://login.eveonline.com/oauth/token");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerData);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($bodyData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
//Server response json decode & display
$result = json_decode($result, true);
//print_r($result);
Now what?
Well I can save the Access Token and the Refresh Token SSO replied with, lets do that.
$access_token = $result['access_token'] ;
$refresh_token = $result['refresh_token'];
I don’t understand what happens next.
Am I supposed to be able to use the Access Token to query ESI now?
What does the refresh token even do?