These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

Looking for a SSO PHP script

First post
Author
Gas
Sebiestor Tribe
Minmatar Republic
#1 - 2015-01-17 10:45:35 UTC
I will tip nicely for the following PHP script. A couple of things first:

Don't direct me to some pre-existing library or other website, i've been doing this for hours.

Just post the script please.

I'm looking for a PHP script that will do a SSO login with a specified Client ID and Secret Key and then
retrieve the regional market data for any single item(lets say rifters). All the market data will then be assigned to
a variable, so I can just vardump that variable and see it.

I just want to run this on my local machine and test things out, so security isn't important. Also if you could specify
exactly how the callback URL should be setup specifically that would be great. Not clear if I need to specify a
callback port. Like localhost:80, not sure how this is setup exactly.

My specifications are as follows:

The entire script must be contained in 1 file only.

No classes used, functions OK.

Thanks in advance if you can help me with this.
Aineko Macx
#2 - 2015-01-17 14:49:16 UTC
I'm not sure why you would (want to) constrain the possible solutions that much. CREST is not exactly trivial and a good client design will certainly have classes.

Nevertheless, the first step of doing what you want is getting a refresh token for your app. Inspired by https://github.com/fuzzysteve/eve-sso-auth I have written a single file procedural webscript that does exactly this: https://gist.github.com/aineko-m/15121de81feee5a66b56#file-getrefreshtoken-php
Just place the file in some webserver, point your browser to it and follow the instructions.

For actual authenticated CREST access, there are libraries, for instance https://github.com/fuzzysteve/CrestLibrary
I'm also in the process of writing my own CREST library, with strong OO design, which should be released in the coming weeks.
Steve Ronuken
Fuzzwork Enterprises
Vote Steve Ronuken for CSM
#3 - 2015-01-17 16:12:15 UTC
I guess you /could/ take the class I wrote for the CrestLibrary, and decompose it down into a single script, with a few global variables and functions (bit painful, but doable)

Though you'd want to strip out all the guzzle code and replace it with something like curl (so you can do the header manipulation required) and strip out stash.

It's a shame you're restricting it so much. Because once you have a refresh token, the example script provided with the library does pretty much what you want.

Woo! CSM XI!

Fuzzwork Enterprises

Twitter: @fuzzysteve on Twitter

Gas
Sebiestor Tribe
Minmatar Republic
#4 - 2015-01-18 04:45:13 UTC  |  Edited by: Gas
I just started at line 0 and I'm halfway there now.

I've got a script to where it will first check to see if it's logged in, if its not logged in it
redirects to the character login screen and then generates a access token.

I'm at this point:

{ access_token: "uNEEh...a_WpiaA2" token_type: "Bearer" expires_in: 300 refresh_token: null }


BTW I couldn't get either of your guys code working. Your CURL setups came in quite handy Bear

Now i'm stumbling around again trying to figure out how to properly setup these GET requests to actually
pull down the market data.
Steve Ronuken
Fuzzwork Enterprises
Vote Steve Ronuken for CSM
#5 - 2015-01-18 17:58:14 UTC
When you want to work with the market data, you have to request with the publicData scope (in the redirect url)

That will give you a refresh token. If you're not getting one, you're not asking for the scope.

Once you have the refresh token, you can just ask for a new access token, on demand, without logging in again. (remember to store it, and the expiry time, and check if it's expired yet, before making any other requests. My library does that.)

Woo! CSM XI!

Fuzzwork Enterprises

Twitter: @fuzzysteve on Twitter

Gas
Sebiestor Tribe
Minmatar Republic
#6 - 2015-01-18 22:18:24 UTC
Yeah setting "scope=publicData" returned a refresh token.


BTW this is the apache error I get when running your library. I installed it exactly as specified.

I'm at a loss, I don't even know where to really begin to trouble shoot this.



Sun Jan 18 17:10:02.281250 2015] [:error] [pid 2824:tid 472] [client 127.0.0.1:4451] PHP Fatal error: Uncaught exception 'GuzzleHttp\\Ring\\Exception\\RingException' with message 'cURL error 60: See http://curl.haxx.se/libcurl/c/libcurl-errors.html' in G:\\SERVER\\UniServerZ\\www\\work3\\vendor\\guzzlehttp\\ringphp\\src\\Client\\CurlFactory.php:126\nStack trace:\n#0 G:\\SERVER\\UniServerZ\\www\\work3\\vendor\\guzzlehttp\\ringphp\\src\\Client\\CurlFactory.php(90): GuzzleHttp\\Ring\\Client\\CurlFactory::createErrorResponse(Object(GuzzleHttp\\Ring\\Client\\CurlMultiHandler), Array, Array)\n#1 G:\\SERVER\\UniServerZ\\www\\work3\\vendor\\guzzlehttp\\ringphp\\src\\Client\\CurlMultiHandler.php(233): GuzzleHttp\\Ring\\Client\\CurlFactory::createResponse(Object(GuzzleHttp\\Ring\\Client\\CurlMultiHandler), Array, Array, Array, Resource id #63)\n#2 G:\\SERVER\\UniServerZ\\www\\work3\\vendor\\guzzlehttp\\ringphp\\src\\Client\\CurlMultiHandler.php(125): GuzzleHttp\\Ring\\Client\\CurlMultiHandler->processMessages()\n#3 G:\\SERVER\\UniServerZ\\www\\work3\\vendor\\guzzlehttp\\ringphp\\src\\Future\\BaseFutureTrait.php(118): GuzzleHttp\\Ring\\Client\\CurlMultiHandler->execute()\n#4 G:\\SERVER\\UniServerZ in G:\\SERVER\\UniServerZ\\www\\work3\\vendor\\guzzlehttp\\guzzle\\src\\Exception\\RequestException.php on line 51, referer: http://localhost/work3/
Steve Ronuken
Fuzzwork Enterprises
Vote Steve Ronuken for CSM
#7 - 2015-01-18 23:00:36 UTC
Ahh, I've seen problems that way. It tends to happen when the certificate for authentication isn't valid. you need to specify your cacerts file. http://curl.haxx.se/ca/cacert.pem should work.


When you're creating the guzzle client, you'll need to add a new option.



$client = new GuzzleHttp\Client([
    'defaults' => [
        "verify" => "/path/to/my/ca-bundle.crt"
    ]
]);




so:


$this->guzzle_client=new \GuzzleHttp\Client([
'base_url' => $urlbase,
'defaults' => [
'headers' => [
'User-Agent' => $this->useragent
]
]
]);



becomes


$this->guzzle_client=new \GuzzleHttp\Client([
'base_url' => $urlbase,
'defaults' => [
'headers' => [
'User-Agent' => $this->useragent
],
'verify" => "whereever you stuck the cacerts file from before."
]
]);


Woo! CSM XI!

Fuzzwork Enterprises

Twitter: @fuzzysteve on Twitter

Gas
Sebiestor Tribe
Minmatar Republic
#8 - 2015-01-19 01:21:28 UTC
That fix worked pretty well from what I can tell, thanks.

I'm assuming these errors are because it's not connecting to the server correctly? I've redid the refresh token a
couple of times. I made the token on https://login-tq.eveonline.com/ and thats what I have set in the setup file.


[Sun Jan 18 20:14:59.828125 2015] [:error] [pid 2824:tid 472] [client 127.0.0.1:1593] PHP Notice: Trying to get property of non-object in G:\\SERVER\\UniServerZ\\www\\work3\\vendor\\fuzzysteve\\crestlibrary\\src\\CrestLibrary\\Client.php on line 153, referer: http://localhost/work3/
[Sun Jan 18 20:15:00.890625 2015] [:error] [pid 2824:tid 472] [client 127.0.0.1:1593] PHP Notice: Trying to get property of non-object in G:\\SERVER\\UniServerZ\\www\\work3\\vendor\\fuzzysteve\\crestlibrary\\src\\CrestLibrary\\Client.php on line 55, referer: http://localhost/work3/
[Sun Jan 18 20:15:00.890625 2015] [:error] [pid 2824:tid 472] [client 127.0.0.1:1593] PHP Warning: Invalid argument supplied for foreach() in G:\\SERVER\\UniServerZ\\www\\work3\\vendor\\fuzzysteve\\crestlibrary\\src\\CrestLibrary\\Client.php on line 55, referer: http://localhost/work3/
[Sun Jan 18 20:15:00.890625 2015] [:error] [pid 2824:tid 472] [client 127.0.0.1:1593] PHP Notice: Undefined index: Sinq Laison in G:\\SERVER\\UniServerZ\\www\\work3\\vendor\\fuzzysteve\\crestlibrary\\src\\CrestLibrary\\Client.php on line 185, referer: http://localhost/work3/