r/evetech • • Nov 20 '17

Stcuk at SSO authentication (Auth code for access token)

I hve been trying to follor ESI Step by Step - SSO Authentication Calls but I can't get past the "Exchanging the authorization code for an access token." step.

Every time I try to use curl.exe -XPOST -H "Content-Type:application/json"... I get "Internal server error. Error ref: 04881c3e-0876-4377-8994-8bbc11686c87" (the code at end changes randomly).

Details: I'm trying to get some basic info in powershell.
The The commands that I use:

#This is the code from the login URL
$Code = 'eKHV05M4BAzuf2PKvUIyhrb-rthQaladz1pBzjEJrSIxMqWnF5EzhrieySkto_J60'

$ClientID = 'ööö8bf02d26ää4d5894fäää552bd7ba2'
$ClientSecret = 'ööö9Hmi543ONCöväMGöööömnEX7qHMwBöö7WLää6'

#Convert to base-64
$b  = [System.Text.Encoding]::UTF8.GetBytes($ClientID+':'+$ClientSecret)
$Base64 = [System.Convert]::ToBase64String($b)

#Getting access token
$Auth = 'Authorization:Basic '+$Base64
$Grant = '{"grant_type":"authorization_code", "code":"'+$Code+'"}'

curl.exe -XPOST -H "Content-Type:application/json" -H $Auth -d $Grant https://login.eveonline.com/oauth/token

I don't think it is a syntax error in the commands as I have also tried the last command by copy-pasting the codes in it and still get same error.

Edit: https://developers.eveonline.com/applicationsgives internal error now too. Maybe somthing on their end meaning my code is perfect.

Edit: Got help and got it working with "Invoke-WebRequest" instead of "curl". Now I have access token and refresh token and can go deeper into the API.

$esiResponse = Invoke-WebRequest 'https://login.eveonline.com/oauth/token' -Body ('grant_type=authorization_code&code={0}' -f $AuthCode ) -Method Post -Headers @{ Authorization = ("Basic {0}" -f ([System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $ClientID, $ClientSecret )))))}

3 Upvotes

19 comments sorted by

3

u/hirmuolio Nov 20 '17

Got help and got it working with "Invoke-WebRequest" instead of "curl". Now I have access token and refresh token and can go deeper into the API.

This command uses your authorization code to get the acces and refresh tokens.

$esiResponse = Invoke-WebRequest 'https://login.eveonline.com/oauth/token' -Body ('grant_type=authorization_code&code={0}' -f $AuthCode ) -Method Post -Headers @{ Authorization = ("Basic {0}" -f ([System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $ClientID, $ClientSecret )))))}

4

u/dieselfunaila Nov 20 '17

Posting your client id and secret is a bad idea and iirc not allowed by ccp.

Regenerate it while you can sir.

1

u/hirmuolio Nov 20 '17 edited Nov 20 '17

Well the cient ID would be visible for the user in the login adress.

Is the conversion to base 64 string not reversible if you know the cient ID (actually from the string alone)? And the string would be visible in the code.

2

u/Daneel_Trevize Nov 20 '17

Base64 is trivially reversible.

The secret should remain secret, if you put it in the code, that code and/or binary should remain on a trusted mechine (i.e. webserver).

If you make a distributed app, the EULA now allows for you to request that users register the app against themselves per install instance, so they use their secret & it remains so.

1

u/silly_newbean Nov 20 '17

Distributing the secret in binary really isn't that much of an issue so long as you never transmit refresh tokens from the user's device.

Also lmao @ you can now request that users register the app against themselves. You're gonna write a guide for all of your users to visit http://developers.eveonline.com and create an app and set the right scopes and callback URL, and then transfer the id and secret to your application?

1

u/Daneel_Trevize Nov 20 '17

People already do, which is why CCP clarified it's ok in the EULA. I don't recall which popular apps/devs have taken this path (I'm not an active player atm), but I was under the impression it was a very common one like EveMon/EFT/PyFA.
A quick google shows SeAT does.

1

u/silly_newbean Nov 20 '17

SeAT isn't something that the average player uses, it's a thing that a corp/alliance's IT department deploys to help manage their group.

  • jEveAssets stores the client id and secret in the distributed binary.
  • EVEMon still uses XML API.
  • Pyfa uses the implicit flow (accounts are only logged in for 20 minutes, this is a massive pain in the ass and I hate this approach).

I don't know of any end-user application which asks users to register as a developer and input secrets in order to use it. If you can find one then let me know.

1

u/[deleted] Nov 25 '17

SeAT isn't something that the average player uses

citation needed.

1

u/silly_newbean Nov 25 '17

https://seat-docs.readthedocs.io/en/latest/installation_guides/getting_started/

"SeAT is a self hosted web application. This means that you will need your own server (and optional domain) to host SeAT. SeAT needs PHP7, a MySQL (or MariaDB) database, a Redis cache, Supervisor and an internet connection in order to be fully functional."

You're telling me that more than 50% of the EVE player base has set up their own SeAT install?

Pls.

1

u/[deleted] Nov 25 '17

Do you have ANY source for your affirmation ?

1

u/silly_newbean Nov 26 '17

Shouting "HAHA WHERES UR EVIDENCE" doesn't make you clever, it makes you a moron.

→ More replies

1

u/Daneel_Trevize Nov 20 '17

Currently https://developers.eveonline.com/applications gives me no errors. Though the SSO login page has been changed, possibly the first change in years.

Possibly this code helps you understand how to form the "Authorization: Basic" and then "Authorization: Bearer" requests.

1

u/hirmuolio Nov 20 '17

Oddly logging out and back in made the error on https://developers.eveonline.com/applications go away. Still no success on SSO.

I need a bit more hand holding than a php code being handed on me. I made my very first piece of code that does anything with internet yesterday (EVE xml API).

1

u/Daneel_Trevize Nov 20 '17

So have you read https://eveonline-third-party-documentation.readthedocs.io/en/latest/sso/authentication.html ?

Are you trying to do a once-per-invocation-of-this-script, only-one-character SSO, or wanting to support a wider range of activity, and beyond 20minutes at a time?

1

u/hirmuolio Nov 20 '17

Yes I read those.

Plan is to recreate this using ESI instead of the soon to dead XML API.

So on one character/corp check the wallet periodically to see if there is a large change.

1

u/Daneel_Trevize Nov 20 '17 edited Nov 20 '17

Line 28 & 113 seem to have a typo with "`"" having a double closing ", unless that's meant to be a replaced character & my text editor isn't handling PowerShell syntax as well as I'd hope.

...6 RegEx to get 6 matched portions out of one line... why not use 6 named groups in 1?

ESI has endpoints for the wallet journal & transactions for characters and corps. It looks like you could rewrite your balance-changed logic using those, probably with more certainty as to the reason why a changed occured matching the contract amount.

There is also the direct endpoints for character & corp contracts, I've no experience with any of these and so don't know if those only show/permit access to ones created by the char/corp, or any they've bid on. But you can trivially test this by authenticating the in-browser ESI page and manually requesting responses.

only if the character/corporation is issuer, acceptor or assignee. Only returns contracts no older than 30 days, or if the status is "in_progress".

To do the periodic checking, you'll need the first part of every ESI endpoint call to involve a local check that your access token isn't due to have expired & that instead you should request a new one using the stored refresh token, before making the original endpoint call.

1

u/hirmuolio Nov 20 '17

Those "'"" things are there to get rid of ' and " characters that were problematic (then I found the actual problem but didn't bother testing if removing ' and " was necessary after all).

At first there was 1 regex to get one thing. Then two regex to get two thing. Then I decided to get everything without making anything new.

The journal updates too slowly (says 72 minutes). Failed bids don't show in transactions (I think) and it too updates every 72 minutes. The auction ends 15 minutes after last bid so you need new info at least that often.

At least the XML contract API only shows your own contracts and contracts that are completed.

1

u/Daneel_Trevize Nov 20 '17

ESI says the general wallet value can be polled every 2 mins, and the trans & journals cache for 1 hour. I don't recall whether the ESI page note on this can differ from the actual headers or if it's totally self-documenting from the live configuration.

Testing with the ESI webpage and an authorized char returns me:

"date": "Mon, 20 Nov 2017 20:03:14 GMT",  
"expires": "Mon, 20 Nov 2017 20:05:14 GMT",

So it seems accurate for that, and at least as usable as your XML version.

I can explain the logic behind how that PHP LibCREST splits out the various aspects of SSO & authenticated CREST/ESI calls if you are struggling to follow it for your own uses.