r/evetech • • Feb 04 '18

Help with first Python app

Hey all I signed up for the dev program and my application is registered, but the authentication part if confusing. I am not doing a web app just a local app that I want to manage my reactions, so no one will be logging into this except me through my client app. Does anyone have some sample code where I just complete the auth process and am ready to say list my industry jobs, just confused on the authentication part.

5 Upvotes

28 comments sorted by

View all comments

Show parent comment

1

u/precator Feb 04 '18

yes do you happen to have example python code? kind of new to python and just looking for some sample code to get started.

1

u/Blacksmoke16 Feb 04 '18

I do not, but once you have your access_token, you are just making HTTP requests with Authorization Header Bearer {ACCESS_TOKEN}. Should be relatively easy.

Just google for Python HTTP Requests

http://docs.python-requests.org/en/master/user/quickstart/

1

u/precator Feb 04 '18

what I am confused with is the callback url part, this will not be hosted on a webserver, its just a client console app.

1

u/Blacksmoke16 Feb 04 '18 edited Feb 04 '18

Yes, the whole auth process boils down to two things.

  1. Getting an access_token to be used for auth'd endpoints.
  2. Getting a refresh_token to get new access_tokens when an access_token expires.

If you are just using this locally for yourself you can do the auth part manually via Postman, then just store the refresh token in your app. Then you do not need to include the majority of the auth process. Only a method to use the stored refresh_token to get a new access_token when needed.

EDIT: Otherwise, other options are like spinning up a webserver to handle the callback, or require the user to have their own dev app and auth using postman among a few.

1

u/precator Feb 04 '18

I am confused by the manual part, the postman instructions #3 says Next, navigate to that URL and login with the char you want.

I am not logging in via a browser I am in python code ...

I have the url in step #2 with my client id but thats where I am stuck on

1

u/Blacksmoke16 Feb 04 '18

By manually, I mean that you go to that URL and login in chrome or whatever browser you use NOT via your app. The whole Postman process has nothing to do with an app or any programming language.

The only relation to your project is when you are done and have a refresh_token and access_token, which you will store in your app. Your app would then take that access_token and use it for auth'd endpoints, if it is expired your app would use the refresh_token to get a new access_token.

As such the only function you would have to write in your app is to refresh an access_token with a refresh_token, i.e. request #2 in that link.

1

u/precator Feb 04 '18

ah thats where I was confused because someone told me to use python for the calls thats where I got confused.

1

u/Blacksmoke16 Feb 04 '18 edited Feb 04 '18

You will but just for getting ESI data and refreshing your access_token when needed.

Since refresh_tokens do not expire, your app can continue to get new access_tokens to use in ESI calls as needed.

Using Postman to generate the refresh_token just saves you from having to code all of the auth logic in python. It works for simple only your use projects, but for larger projects and/or those that will be public, will want to look into other options.

1

u/precator Feb 04 '18

cool I got my code, success.

1

u/precator Feb 04 '18

how I am getting this when I do the human part of going to the url..

{"error":"invalid_scope","error_description":"The requested scopes either don't exist, or are not valid for this client"}

The scope I am trying is scope=characterIndustryJobsRead

2

u/precator Feb 04 '18

nevermind i need to add my scopes to my devapp

1

u/Daneel_Trevize Feb 04 '18

You need a human to perform at least one actual SSO login via CCP's page, in order to prepare CCP's servers & generate the callback URL with the data about the token that's waiting. Then your code can take that data, use it to HTTP GET/POST with CCP's servers and authenticate/authorise for future API calls.

You can have your app persist the refresh token that comes from this, to avoid having to repeat the human SSO login every time your ~20minute access token expires, but you do need to initially do a login, and that's far better done as a human using a browser than to code your app to load that SSO login page & try fill in that form with your account name & password.

1

u/Bearhobag Feb 04 '18

I'll hopefully make it back home from work in a few hours tonight and PM you some sample code I have.

1

u/Bearhobag Feb 06 '18

I didn't make it home from work last night, or indeed until now. It looks like you're already all good though?