def restful_auth(request, option): timestamp = CEIUtils.get_now("%Y':'%m':'%d'T'#H':'%M':'%S") request.add_query_string("AccessKeyId", option.api_key) request.add_query_string("SignatureMethod", "HmacSHA256") request.add_query_string("SignatureVersion", "2") request.add_query_string("Timestamp", timestamp) query_string = CEIUtils.combine_query_string(request, CEIUtils.Constant.ASC, "&") method = CEIUtils.get_request_info(request, CEIUtils.Constant.METHOD, CEIUtils.Constant.UPPERCASE) host = CEIUtils.get_request_info(request, CEIUtils.Constant.HOST, CEIUtils.Constant.NONE) target = CEIUtils.get_request_info(request, CEIUtils.Constant.TARGET, CEIUtils.Constant.NONE) buffer = StringWrapper() buffer.append_string_item(method) buffer.append_string_item(host) buffer.append_string_item(target) buffer.append_string_item(query_string) buffer.combine_string_items("", "", "\\n") hmacsha256 = CEIUtils.hmacsha256(buffer.to_string(), option.secret_key) result = CEIUtils.base64(hmacsha256) request.add_query_string("Signature", result)
def restful_auth(request, option): request.add_header_string("X-MBX-APIKEY", option.api_key) ts = CEIUtils.get_now("Unix_ms") request.add_query_string("timestamp", ts) query_string = CEIUtils.combine_query_string(request, CEIUtils.Constant.NONE, "&") post_body = CEIUtils.get_request_info(request, CEIUtils.Constant.POSTBODY, CEIUtils.Constant.NONE) buffer = StringWrapper() buffer.append_string_item(query_string) buffer.append_string_item(post_body) buffer.combine_string_items("", "", "") hmac = CEIUtils.hmacsha256(buffer.to_string(), option.secret_key) output = CEIUtils.hex(hmac) request.add_query_string("signature", output)