Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d32e0e5
commit b23fd85
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# 1) Configure below | ||
# 2) pip install esipy Flask | ||
# 3) FLASK_APP=tokenfetcher.py flask run | ||
# 4) Wait a couple of seconds for the browser to open | ||
|
||
import webbrowser | ||
|
||
from esipy import App | ||
from esipy import EsiClient | ||
from esipy import EsiSecurity | ||
|
||
from flask import Flask, request | ||
|
||
CLIENT_ID = '' | ||
SECRET_KEY = '' | ||
SCOPES = ['esi-universe.read_structures.v1', 'esi-markets.structure_markets.v1'] | ||
|
||
app = Flask(__name__) | ||
esi_app = App.create(url="https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility") | ||
|
||
security = EsiSecurity( | ||
app=esi_app, | ||
redirect_uri='http://127.0.0.1:5000/ESICallback', | ||
client_id=CLIENT_ID, | ||
secret_key=SECRET_KEY | ||
) | ||
|
||
client = EsiClient( | ||
retry_requests=True, | ||
header={'User-Agent': 'ESI Token Fetcher'}, | ||
security=security | ||
) | ||
|
||
webbrowser.open_new(security.get_auth_uri(scopes=SCOPES)) | ||
|
||
@app.route('/ESICallback') | ||
def esi_callback(): | ||
code = request.args.get('code', '') | ||
|
||
if code: | ||
tokens = security.auth(code) | ||
return str(tokens) | ||
else: | ||
return 'No code returned!' | ||
|