예제 #1
0
파일: server.py 프로젝트: wuhuaping/lbry
 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')
예제 #2
0
파일: client.py 프로젝트: bitspill/lbry
    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']
예제 #3
0
파일: client.py 프로젝트: Fillerix99/lbry
    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']
예제 #4
0
파일: client.py 프로젝트: lbryio/lbry
    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"]
예제 #5
0
파일: server.py 프로젝트: bitspill/lbry
 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
예제 #6
0
파일: server.py 프로젝트: Fillerix99/lbry
 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