additional error handling
This commit is contained in:
@@ -11,7 +11,7 @@ import webbrowser
|
||||
import eos.db
|
||||
from service.const import EsiLoginMethod, EsiSsoMode
|
||||
from eos.saveddata.ssocharacter import SsoCharacter
|
||||
from service.esiAccess import APIException, SSOError
|
||||
from service.esiAccess import APIException, GenericSsoError
|
||||
import gui.globalEvents as GE
|
||||
from gui.ssoLogin import SsoLogin, SsoLoginServer
|
||||
from service.server import StoppableHTTPServer, AuthHandler
|
||||
@@ -141,7 +141,7 @@ class Esi(EsiAccess):
|
||||
|
||||
sub_split = data["sub"].split(":")
|
||||
if (len(sub_split) != 3):
|
||||
raise SSOError("JWT sub does not contain the expected data. Contents: %s" % data["sub"])
|
||||
raise GenericSsoError("JWT sub does not contain the expected data. Contents: %s" % data["sub"])
|
||||
cid = sub_split[-1]
|
||||
if currentCharacter is None:
|
||||
currentCharacter = SsoCharacter(cid, data['name'], config.getClientSecret())
|
||||
@@ -155,17 +155,17 @@ class Esi(EsiAccess):
|
||||
|
||||
def handleServerLogin(self, message):
|
||||
if not message:
|
||||
raise SSOError("Could not parse out querystring parameters.")
|
||||
raise GenericSsoError("Could not parse out querystring parameters.")
|
||||
|
||||
try:
|
||||
state_enc = message['state']
|
||||
state = json.loads(base64.b64decode(state_enc))['state']
|
||||
except Exception:
|
||||
raise SSOError("There was a problem decoding state parameter.")
|
||||
raise GenericSsoError("There was a problem decoding state parameter.")
|
||||
|
||||
if state != self.state:
|
||||
pyfalog.warn("OAUTH state mismatch")
|
||||
raise SSOError("OAUTH State Mismatch.")
|
||||
raise GenericSsoError("OAUTH State Mismatch.")
|
||||
|
||||
pyfalog.debug("Handling SSO login with: {0}", message)
|
||||
|
||||
|
||||
@@ -20,13 +20,10 @@ from datetime import timedelta
|
||||
from requests_cache import CachedSession
|
||||
|
||||
from requests import Session
|
||||
from urllib.parse import urlencode, quote
|
||||
from urllib.parse import urlencode
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
class SSOError(Exception):
|
||||
pass
|
||||
|
||||
scopes = [
|
||||
'esi-skills.read_skills.v1',
|
||||
'esi-fittings.read_fittings.v1',
|
||||
@@ -40,9 +37,13 @@ supported_servers = {
|
||||
"Serenity": ApiBase("login.evepc.163.com", "esi.evepc.163.com")
|
||||
}
|
||||
|
||||
class GenericSsoError(Exception):
|
||||
""" Exception used for generic SSO errors that aren't directly related to an API call
|
||||
"""
|
||||
pass
|
||||
|
||||
class APIException(Exception):
|
||||
""" Exception for SSO related errors """
|
||||
""" Exception for API related errors """
|
||||
|
||||
def __init__(self, url, code, json_response):
|
||||
self.url = url
|
||||
@@ -50,10 +51,11 @@ class APIException(Exception):
|
||||
self.response = json_response
|
||||
super(APIException, self).__init__(str(self))
|
||||
|
||||
|
||||
def __str__(self):
|
||||
if 'error' in self.response:
|
||||
if 'error_description' in self.response:
|
||||
return 'HTTP Error %s: %s' % (self.status_code,
|
||||
self.response['error'])
|
||||
self.response['error_description'])
|
||||
elif 'message' in self.response:
|
||||
return 'HTTP Error %s: %s' % (self.status_code,
|
||||
self.response['message'])
|
||||
@@ -163,7 +165,6 @@ class EsiAccess:
|
||||
return {'Authorization': 'Bearer %s' % token}
|
||||
|
||||
def auth(self, code):
|
||||
# todo: properly handle invalid auth code, or one that has been used already
|
||||
values = {
|
||||
'grant_type': 'authorization_code',
|
||||
'code': code,
|
||||
@@ -223,7 +224,7 @@ class EsiAccess:
|
||||
try:
|
||||
jwk_sets = self.jwks["keys"]
|
||||
except KeyError as e:
|
||||
raise SSOError("Something went wrong when retrieving the JWK set. The returned "
|
||||
raise GenericSsoError("Something went wrong when retrieving the JWK set. The returned "
|
||||
"payload did not have the expected key {}. \nPayload returned "
|
||||
"from the SSO looks like: {}".format(e, self.jwks))
|
||||
|
||||
@@ -237,11 +238,11 @@ class EsiAccess:
|
||||
issuer=[self.server_base.sso, "https://%s" % self.server_base.sso]
|
||||
)
|
||||
except ExpiredSignatureError as e:
|
||||
raise SSOError("The JWT token has expired: {}").format(str(e))
|
||||
raise GenericSsoError("The JWT token has expired: {}".format(str(e)))
|
||||
except JWTError as e:
|
||||
raise SSOError("The JWT signature was invalid: {}").format(str(e))
|
||||
raise GenericSsoError("The JWT signature was invalid: {}".format(str(e)))
|
||||
except JWTClaimsError as e:
|
||||
raise SSOError("The issuer claim was not from login.eveonline.com or "
|
||||
raise GenericSsoError("The issuer claim was not from login.eveonline.com or "
|
||||
"https://login.eveonline.com: {}".format(str(e)))
|
||||
|
||||
def _before_request(self, ssoChar):
|
||||
|
||||
@@ -5,8 +5,9 @@ import threading
|
||||
from logbook import Logger
|
||||
import socketserver
|
||||
import json
|
||||
import traceback
|
||||
|
||||
from service.esiAccess import APIException, SSOError
|
||||
from service.esiAccess import APIException, GenericSsoError
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
@@ -33,10 +34,10 @@ class AuthHandler(http.server.BaseHTTPRequestHandler):
|
||||
self.end_headers()
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except (SSOError, APIException) as ex:
|
||||
except (GenericSsoError, APIException) as ex:
|
||||
pyfalog.error("Error logging into EVE")
|
||||
pyfalog.error(ex)
|
||||
self.send_response(500)
|
||||
self.send_response(400)
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
self.end_headers()
|
||||
self.wfile.write(str.encode(str(ex)))
|
||||
@@ -46,6 +47,8 @@ class AuthHandler(http.server.BaseHTTPRequestHandler):
|
||||
self.send_response(500)
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
self.end_headers()
|
||||
self.wfile.write(str.encode(str(''.join(traceback.format_tb(ex.__traceback__)))))
|
||||
|
||||
# send error
|
||||
|
||||
if is_success:
|
||||
|
||||
Reference in New Issue
Block a user