def _verify_token(self, session_id, message, token): if token is None: raise InvalidAuthenticationToken('Authentication token not found') to_auth = get_auth_message(message) api_key = self.sessions.get(session_id) if not api_key.compare_hmac(to_auth, token): raise InvalidAuthenticationToken('Invalid authentication token')
def __call__(self, *args): self.__id_count += 1 pre_auth_postdata = { 'version': '1.1', 'method': self.__service_name, 'params': args, 'id': self.__id_count } to_auth = get_auth_message(pre_auth_postdata) token = self.__api_key.get_hmac(to_auth) pre_auth_postdata.update({'hmac': token}) postdata = json.dumps(pre_auth_postdata) service_url = self.__service_url auth_header = self.__auth_header cookies = self.__cookies host = self.__url.hostname req = requests.Request(method='POST', url=service_url, data=postdata, headers={ 'Host': host, 'User-Agent': USER_AGENT, 'Authorization': auth_header, 'Content-type': 'application/json' }, cookies=cookies) r = req.prepare() http_response = self.__conn.send(r) cookies = http_response.cookies headers = http_response.headers next_secret = headers.get(LBRY_SECRET, False) if next_secret: self.__api_key.secret = next_secret self.__cookies = cookies if http_response is None: raise JSONRPCException({ 'code': -342, 'message': 'missing HTTP response from server' }) http_response.raise_for_status() response = http_response.json() if response['error'] is not None: raise JSONRPCException(response['error']) elif 'result' not in response: raise JSONRPCException({ 'code': -343, 'message': 'missing JSON-RPC result' }) else: return response['result']
def call(self, method, params={}): self.__id_count += 1 pre_auth_post_data = { 'version': '1.1', 'method': method, 'params': params, 'id': self.__id_count } to_auth = get_auth_message(pre_auth_post_data) token = self.__api_key.get_hmac(to_auth) pre_auth_post_data.update({'hmac': token}) post_data = json.dumps(pre_auth_post_data) service_url = self.__service_url auth_header = self.__auth_header cookies = self.__cookies host = self.__url.hostname req = requests.Request(method='POST', url=service_url, data=post_data, headers={ 'Host': host, 'User-Agent': USER_AGENT, 'Authorization': auth_header, 'Content-type': 'application/json' }, cookies=cookies) r = req.prepare() http_response = self.__conn.send(r) cookies = http_response.cookies headers = http_response.headers next_secret = headers.get(LBRY_SECRET, False) if next_secret: self.__api_key.secret = next_secret self.__cookies = cookies if http_response is None: raise JSONRPCException({ 'code': -342, 'message': 'missing HTTP response from server'}) http_response.raise_for_status() response = http_response.json() if response['error'] is not None: raise JSONRPCException(response['error']) elif 'result' not in response: raise JSONRPCException({ 'code': -343, 'message': 'missing JSON-RPC result'}) else: return response['result']
def __call__(self, *args): self.__id_count += 1 pre_auth_postdata = {"version": "1.1", "method": self.__service_name, "params": args, "id": self.__id_count} to_auth = get_auth_message(pre_auth_postdata) token = self.__api_key.get_hmac(to_auth) pre_auth_postdata.update({"hmac": token}) postdata = json.dumps(pre_auth_postdata) service_url = self.__service_url auth_header = self.__auth_header cookies = self.__cookies host = self.__url.hostname req = requests.Request( method="POST", url=service_url, data=postdata, headers={ "Host": host, "User-Agent": USER_AGENT, "Authorization": auth_header, "Content-type": "application/json", }, cookies=cookies, ) r = req.prepare() http_response = self.__conn.send(r) cookies = http_response.cookies headers = http_response.headers next_secret = headers.get(LBRY_SECRET, False) if next_secret: self.__api_key.secret = next_secret self.__cookies = cookies if http_response is None: raise JSONRPCException({"code": -342, "message": "missing HTTP response from server"}) http_response.raise_for_status() response = http_response.json() if response["error"] is not None: raise JSONRPCException(response["error"]) elif "result" not in response: raise JSONRPCException({"code": -343, "message": "missing JSON-RPC result"}) else: return response["result"]
def _verify_token(self, session_id, message, token): to_auth = get_auth_message(message) api_key = self.sessions.get(session_id) assert api_key.compare_hmac(to_auth, token), InvalidAuthenticationToken
def _verify_token(self, session_id, message, token): assert token is not None, InvalidAuthenticationToken to_auth = get_auth_message(message) api_key = self.sessions.get(session_id) assert api_key.compare_hmac(to_auth, token), InvalidAuthenticationToken