Error 403 when trying to connect to websocket api - unificationengine

I currently develop a realtime kik connector for the unification engine.To receive the messages, I connect to the websocket endpoint using my users name and password.Sadly, I get an error 403 everytime.Is there anything else I have to look out for?
Some examples:
$ curl -XPOST https://apiv2.unificationengine.com/v2/connection/list -u $USER_NAME:$PASSWORD --data "{}" -k -s | jq
{
"status": 200,
"info": "200 OK",
"connections": {
"kik": {
"uri": "kik://kik_user#kik.com"
}
}
}
Websocket:
$ wscat --auth "$USER_NAME:$PASSWORD" -c wss://apiv2.unificationengine.com/v2/ws/start
error: Error: unexpected server response (403)

Are you using this library?
https://github.com/websockets/wscat
Does this library support authentication in this way?
wscat --auth "$USER_NAME:$PASSWORD" -c wss://apiv2.unificationengine.com/v2/ws/start
Done research on this, wscat is using npm ws, https://github.com/websockets/ws for webscoket connection.
Can you try header like this and check
var ws = new WebSocket('wss://apiv2.unificationengine.com/v2/ws/start', {
origin: 'https://apiv2.unificationengine.com',
headers: { Authorization: 'base64 auth' }
});
You can create base64 auth like this in nodejs
var auth = "Basic " + new Buffer(USER_ACCESS_KEY + ":" + USER_ACCESS_SECRET).toString("base64");

Related

Failed executing transaction to invoke HyperLedger Fabric function using Kaliedo FabConnect API

I've been using Kaleido's FabConnect API to invoke some transactions from a sample fabric smart contract using this request:
curl -X 'POST'
'https://u0jzrmv8ok-u0nh6n12o1-connect.us0-aws-ws.kaleido.io/transactions?fly-sync=true'
-H 'accept: /'
-H 'Content-Type: application/json'
-d '{
"headers": {
"type": "SendTransaction",
"signer": "user2",
"channel": "ustrades",
"chaincode": "asset_transfer"
},
"func": "GetAllAssets",
"args": [
"string"
],
"init": false
}'
but I get the following error: {
"error": "Failed to submit: error getting channel response for channel [ustrades]: Discovery status Code: (11) UNKNOWN. Description: error received from Discovery Server: failed constructing descriptor for chaincodes:<name:"asset_transfer" > "
}
I've seen a similar problem where the solution offered was to add anchor peer nodes, but how exactly do you do that on Kaleido. Their customer support is slow getting back to me, so I thought I'd ask here.

Github API - add an issue to a project?

Is it possible, using the github API, to add an Issue to a project board?
This document:
https://docs.github.com/en/rest/reference/projects#create-a-project-card
suggests it is possible, but my attempts using https://github.com/fastai/ghapi have failed.
I have tried:
api.projects.create_card(col.id, note=f'{issue.title} {issue.html_url}', content_id=issue.id)
but the card does not show up as an issue card, it shows up as a card referencing an issue - which is different.
I also tried:
curl -X POST -H "Accept: application/vnd.github.v3+json" https://api.github.com/projects/columns/####/cards -d '{"column_id": colid, "content_id": cid, "content_type": "json"}' -u user:$GITHUB_TOKEN
and that gave an error:
{
"message": "Validation Failed",
"errors": [
{
"resource": "ProjectCard",
"code": "unprocessable",
"field": "data",
"message": "Could not resolve to a node with the global id of 'XXXXXXXXXX'."
}
],
"documentation_url": "https://docs.github.com/v3/projects/cards/#create-a-project-card"
}
which suggests that I've mucked up the curl request, but I'm not sure where.
I've found a solution following https://stackoverflow.com/a/57696731/814354. I need to declare the content_type in the POST request (which is information I was unable to find on the github documentation).
CURL version:
curl -X POST -H "Accept: application/vnd.github.v3+json" https://api.github.com/projects/columns/{column_id}/cards -d '{"column_id": {column_id}, "content_id": {issue_id}, "content_type": "Issue"}' -u {username}:$GITHUB_TOKEN
The ghapi version does not work:
# this fails - `content_id` and `content_type` are not included in the request
api.projects.create_card(col.id, content_id=issue.id, content_type='Issue')
but you can still use the ghapi in a clunkier way:
api(path=f'/projects/columns/{col.id}/cards', verb='POST',
data={'content_id': issue.id,
'column_id': col.id,
'content_type': 'Issue'
},
headers={"Accept": "application/vnd.github.v3+json"}
)

Convert curl command into a working script

I am using an API from check-host.net to ping an website.
My issue is right now that I have no ideea how I could transform the curl command api into an working python script. I tried different approaches which I found on here but sadly none has give me the ouput I am looking for.
Working curl command:
curl -H "Accept: application/json" \ https://check-host.net/check-tcp?host=smtp://gmail.com&max_nodes=1
the respons looks something like that:
{ "ok": 1, "request_id": "29", "permanent_link":
"https://check-host.net/check-report/29", "nodes": {
"7f000001": ["it","Italy", "Marco"] } }
You have to send a Accept: application/json header in your request. You can also use the builtin json decoder in requests.
import requests
headers={
'Accept': 'application/json'
}
r=requests.get('https://check-host.net/check-tcp?host=smtp://gmail.com&max_nodes=1',headers=headers)
print(r.json())
Output
{'nodes': {'us2.node.check-host.net': ['us', 'USA', 'New Jersey', '199.38.245.218', 'AS394625', 'OK']}, 'ok': 1, 'permanent_link': 'https://check-host.net/check-report/a462c3ck399', 'request_id': 'a462c3ck399'}

How do I send data to a nodeJS websocket on the command line?

I have a node JS web socket server that is setup like so
// Miner Proxy Srv
var srv = new WebSocket.Server({
server: web,
path: "/proxy",
maxPayload: 1024
});
srv.on('connection', (ws) => {
var conn = {
uid: null,
pid: crypto.randomBytes(12).toString("hex"),
workerId: null,
found: 0,
accepted: 0,
ws: ws,
pl: new net.Socket(),
}
My question is how do I connect to the web socket AND send data to it? I downloaded "wscat" and tried the below
wscat -c ws://localhost:8000/proxy -p 13 -H "Host:localhost.localdomain.com" -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" -H "Sec-WebSocket-Version: 13" '{"type":"auth","params":{"site_key":{"IF_EXCLUSIVE_TAB":"ifExclusiveTab","FORCE_EXCLUSIVE_TAB":"forceExclusiveTab","FORCE_MULTI_TAB":"forceMultiTab","CONFIG":{"LIB_URL":"https://localhost.localdomain.com/lib/","WEBSOCKET_SHARDS":[["wss://localhost.localdomain.com/proxy"]]},"CRYPTONIGHT_WORKER_BLOB":"blob:https://localhost.localdomain.com/54f39ac6-5c2a-4ff1-8052-c4e0e508034c"},"type":"anonymous","user":null,"goal":0}}'
but I get the error
error: Error: invalid server key
when I run the above.
wscat generates valid header Sec-WebSocket-Key for the request by default, so just remove -H "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" from the command-line and it might work. I debugged on and found below header are already created even if I dont pass them through command-line using wscat.
srv.on('connection', (ws,req) => {
console.log(req.headers);
/*
//headers present without passing arguments to wscat
{ 'sec-websocket-version': '13',
'sec-websocket-key': 's3pPLMBiTxaQ9kYGzzhZRbK+xOo=',
connection: 'Upgrade',
upgrade: 'websocket',
.....
*/
......
So use following command:
wscat -c ws://localhost:8000/proxy -p 13 -H "Host:localhost.localdomain.com" -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Sec-WebSocket-Version: 13" '{"type":"auth","params":{"site_key":{"IF_EXCLUSIVE_TAB":"ifExclusiveTab","FORCE_EXCLUSIVE_TAB":"forceExclusiveTab","FORCE_MULTI_TAB":"forceMultiTab","CONFIG":{"LIB_URL":"https://localhost.localdomain.com/lib/","WEBSOCKET_SHARDS":[["wss://localhost.localdomain.com/proxy"]]},"CRYPTONIGHT_WORKER_BLOB":"blob:https://localhost.localdomain.com/54f39ac6-5c2a-4ff1-8052-c4e0e508034c"},"type":"anonymous","user":null,"goal":0}}'
I hope it helps.

Passing variables to curl command in child_process.exec fails

I was trying to use child_process.exec to call curl with a long command in order to send some data to an API. Something similar to the following example:
exec('git log --oneline | wc -l', function(error, stdin, stderr) {
if (stdin > 1) {
exec('curl -H "Content-Type: application/json" -X POST -d \'{"value1": "\'"$arg"\'"}\' https://https://maker.ifttt.com/trigger/{event}/with/key/<my-key>', { "env" : {"arg": stdin } });
}
})
So if a git repo includes more than one line in its git log output, then you execute a POST request to some API (here, a simple webhook in ifttt.com), in which you're passing some variable (arg) in the process.
Notice that this is the best attempt, but in general, I was struggling quite a bit to escape single and double quotes. In this particular case, the HTTP request was not sent correctly because the body includes a line break:
POST / HTTP/1.1
Host: <some-host>
User-Agent: curl/7.50.1
Accept: */*
Content-Type: application/json
Content-Length: 16
{"value1": "2
"}
At the end, I had to use an external bash script:
exec('./send_request.sh $arg', { "env": {"arg": stdin } });
but I'm still very curious on how to make it work within the same js file.
If it helps, I'm running node 6.11.0 and curl 7.52.1.
Try:
exec('git log --oneline | wc -l', function(error, stdin, stderr) {
if (stdin > 1) {
exec('curl -H "Content-Type: application/json" -X POST -d \'{"value1": "\'"$arg"\'"}\' https://https://maker.ifttt.com/trigger/{event}/with/key/<my-key>', { "env" : {"arg": stdin.replace(/\n/g, '') } });
}
})
What is happening is that your variable 'stdin' (you should rename it to 'stdout') has a \n at the end of it.

Resources