def __init__(self): try: Esi.initEsiApp() except Exception as e: # todo: this is a stop-gap for #1546. figure out a better way of handling esi service failing. pyfalog.error(e) wx.MessageBox( "The ESI module failed to initialize. This can sometimes happen on first load on a slower connection. Please try again." ) return self.settings = EsiSettings.getInstance() AFTER_TOKEN_REFRESH.add_receiver(self.tokenUpdate) # these will be set when needed self.httpd = None self.state = None self.ssoTimer = None self.implicitCharacter = None # The database cache does not seem to be working for some reason. Use # this as a temporary measure self.charCache = {} # need these here to post events import gui.mainFrame # put this here to avoid loop self.mainFrame = gui.mainFrame.MainFrame.getInstance()
def get_api(fn, scopes): esi_app = App.create( 'https://esi.tech.ccp.is/latest/swagger.json?datasource=tranquility') esi_security = EsiSecurity( app=esi_app, redirect_uri='http://localhost:8080/callback', client_id='0b9ac4978a9a4feba20a7eba4f666a46', secret_key='odtDKZWZbwbFnBHNXnOhRX50YrU49owBw1qE3v7p', ) esi_client = EsiClient(retry_requests=True, security=esi_security) def write_refresh_token(refresh_token, **kwargs): with open(fn, "w") as f: f.write(refresh_token) AFTER_TOKEN_REFRESH.add_receiver(write_refresh_token) if os.path.isfile(fn): with open(fn) as f: token = open(fn).read() esi_security.update_token({ 'access_token': '', 'expires_in': -1, 'refresh_token': token }) tokens = esi_security.refresh() else: print(esi_security.get_auth_uri(scopes=scopes)) tokens = esi_security.auth(input()) write_refresh_token(**tokens) api_info = esi_security.verify() return api_info, esi_app, esi_client
def __call__(self, request): """ Check if the request need security header and apply them. Required for pyswagger.core.BaseClient.request(). :param request: the pyswagger request object to check :return: the updated request. """ if not request._security: return request if self.is_token_expired(): json_response = self.refresh() AFTER_TOKEN_REFRESH.send(**json_response) for security in request._security: if self.security_name not in security: LOGGER.warning( "Missing Securities: [%s]" % ", ".join(security.keys()) ) continue if self.access_token is not None: request._p['header'].update(self.__get_oauth_header()) return request
def invalidate(self, key): cache.delete(_hash(key)) lbcache = LbCache() transport_adapter = HTTPAdapter( pool_connections=20, pool_maxsize=300, ) # ESI objects to be imported esiapp = EsiApp(cache=lbcache, cache_time=0, datasource=config.ESI_DATASOURCE) esisecurity = EsiSecurity( app=esiapp.get_latest_swagger, redirect_uri="%s%s" % ( config.ESI_REDIRECT_DOMAIN, '/sso/callback', ), client_id=config.ESI_CLIENT_ID, secret_key=config.ESI_SECRET_KEY, ) esiclient = EsiClient(security=esisecurity, transport_adapter=transport_adapter, cache=lbcache, headers={'User-Agent': config.ESI_USER_AGENT}) # register observers AFTER_TOKEN_REFRESH.add_receiver(token_update_observer)