Feathersjs verify user via verifySignupShort pin code - feathersjs

I am working on a proof of concept using feathersJS for signing users up via phone number and verifying via sms and pin https://github.com/morenoh149/feathers-chat-phone-signup-sms
Currently I get the following error
$ sh curls/user-verify.sh 118903
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 208 100 156 100 52 17067 5689 --:--:-- --:--:-- --:--:-- 17333
{
"name": "BadRequest",
"message": "Expected string value. (authManagement)",
"code": 400,
"className": "bad-request",
"data": {},
"errors": {
"$className": "badParams"
}
}
the api is using https://github.com/feathers-plus/feathers-authentication-management and I've done my best to adapt it to this use case. My curl looks like
curl --header "Content-Type: application/json" \
--data '{ "action": "verifySignupShort", "value": 12345 }' \
http://localhost:3030/authmanagement

According to the docs The value should be an Object with a user and token. Token should be a string as well.
{
"action": "verifySignupShort",
"value": {
"token": "390494",
"user": {
"phoneNumber": "5005550006"
}
}
}
Docs: https://github.com/feathers-plus/feathers-authentication-management/blob/master/docs.md

Related

Questions on json and GCP

So I have this code to write out a json file to be connected to via endpoint. The file is pretty standard in that it has the location of how to connect to the endpoint as well as some data.
%%writefile default-pred.json
{ PROJECT_ID:"msds434-gcp",
REGION:"us-central1",
ENDPOINT_ID:"2857701089334001664",
INPUT_DATA_FILE:"INPUT-JSON",
"instances": [
{"age": 39,
"bill_amt_1": 47174,
"bill_amt_2": 47974,
"bill_amt_3": 48630,
"bill_amt_4": 50803,
"bill_amt_5": 30789,
"bill_amt_6": 15874,
"education_level": "1",
"limit_balance": 50000,
"marital_status": "2",
"pay_0": 0,
"pay_2":0,
"pay_3": 0,
"pay_4": 0,
"pay_5": "0",
"pay_6": "0",
"pay_amt_1": 1800,
"pay_amt_2": 2000,
"pay_amt_3": 3000,
"pay_amt_4": 2000,
"pay_amt_5": 2000,
"pay_amt_6": 2000,
"sex": "1"
}
]
}
Then I have this trying to connect to the file and then taking the information to connect to the end point in question. I know the information is right as it's the exact code from GCP.
!curl \
-X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-prediction-aiplatform.googleapis.com/v1alpha1/projects/$PROJECT_ID/locations/$REGION/endpoints/$ENDPOINT_ID:predict \
-d "#default-pred.json"
So from the information I have I would expect it to parse the information I have and connect to the endpoint, but obviously I have my file wrong somehow. Any idea what it is?
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"PROJECT_ID\": Cannot find field.\nInvalid JSON payload received. Unknown name \"REGION\": Cannot find field.\nInvalid JSON payload received. Unknown name \"ENDPOINT_ID\": Cannot find field.\nInvalid JSON payload received. Unknown name \"INPUT_DATA_FILE\": Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"PROJECT_ID\": Cannot find field."
},
{
"description": "Invalid JSON payload received. Unknown name \"REGION\": Cannot find field."
},
{
"description": "Invalid JSON payload received. Unknown name \"ENDPOINT_ID\": Cannot find field."
},
{
"description": "Invalid JSON payload received. Unknown name \"INPUT_DATA_FILE\": Cannot find field."
}
]
}
]
}
}
What am I missing here?
The data file should only include the data.
You've included PROJECT_ID, REGION, ENDPOINT and should not.
These need to be set in the (bash) environment before you issue the curl command:
PROJECT_ID="msds434-gcp"
REGION="us-central1"
ENDPOINT_ID="2857701089334001664"
curl \
--request POST \
--header "Authorization: Bearer $(gcloud auth print-access-token)" \
--header "Content-Type: application/json" \
https://us-central1-prediction-aiplatform.googleapis.com/v1alpha1/projects/$PROJECT_ID/locations/$REGION/endpoints/$ENDPOINT_ID:predict \
--data "#default-pred.json"
The file default-pred.json should probably (I can never find this service's methods in APIs Explorer!) just be:
{
instances": [
{ "age": 39,
"bill_amt_1": 47174,
"bill_amt_2": 47974,
"bill_amt_3": 48630,
"bill_amt_4": 50803,
"bill_amt_5": 30789,
"bill_amt_6": 15874,
"education_level": "1",
"limit_balance": 50000,
"marital_status": "2",
"pay_0": 0,
"pay_2":0,
"pay_3": 0,
"pay_4": 0,
"pay_5": "0",
"pay_6": "0",
"pay_amt_1": 1800,
"pay_amt_2": 2000,
"pay_amt_3": 3000,
"pay_amt_4": 2000,
"pay_amt_5": 2000,
"pay_amt_6": 2000,
"sex": "1"
}
]
}
See the documentation for the aiplatform predict method as this explains this.

Filtering JSON curl results with jq selectors

I have the following multi-record JSON structure coming as a response from a web service:
[
{
"model": "analytics.request",
"pk": 89,
"fields": {
"intent": "GetUserAccountInformation",
"sub_intent": "",
"request_text": "what is my balance",
"response_text": "You have $111,111.11 and owe $111,111. Shall I break that down?",
"session_id": "1v69yiptamgse1niap51zr2o9x154169081480766b2d6b7-d3ce-4166-9292-c4669a3dfc14",
"user_id": "amzn1.ask.account.AHMFB2H7ZXMSCB5TLPYWCPBJGWGHFYQZ6OPPMEPQ7CT2LZXNPAFJMJELXXCCTEZ2JUE5PXRSBJHJTO3AVXT3C63AOEZLIEP3D3HIFBT5M23G4ORENFRT54AAK7I4X2HCORXJAB2UGQAHPE2TC75F2GWWZWSPO2CWEAZJJN7LJYFWEYHEJDLNQ6FSUD5LQWKBUC347K3IF32IV3I",
"device_id": "amzn1.ask.account.AHMFB2H7ZXMSCB5TLPYWCPBJGWGHFYQZ",
"device_type": "alexa",
"device_model": "NA",
"device_os": "alexa",
"elapsed_time": 23286,
"region": "NA",
"latitude": 0,
"longitude": 0,
"date": "2018-11-08T15:31:48.757+0000",
"ext_session_id": "",
"ext_user_id": "",
"score": 1,
"platform_type": "alexa",
"platform_user_id": "amzn1.ask.account.AHMFB2H7ZXMSCB5TLPYWCPBJGWGHFYQZ6OPPMEPQ7CT2LZXNPAFJMJELXXCCTEZ2JUE5PXRSBJHJTO3AVXT3C63AOEZLIEP3D3HIFBT5M23G4ORENFRT54AAK7I4X2HCORXJAB2UGQAHPE2TC75F2GWWZWSPO2CWEAZJJN7LJYFWEYHEJDLNQ6FSUD5LQWKBUC347K3IF32IV3I",
"platform_conversation_id": "amzn1.echo-api.session.9122211c-7fa8-43ae-b7e3-e56ebbdacc01",
"registered": false,
"segment_names": [
"Seg0715080610AM",
"Seg0715071857AM",
"Seg0715070437AM",
"Seg0715063307AM",
"Seg0715054215AM",
"Seg0715054027AM",
"Seg0715053845AM",
"Seg0715053646AM",
"Seg0715053156AM",
"Seg0715052407AM",
"Seg0715045748AM",
"Seg0714145246PM",
"Seg0714135150PM",
"Seg0714134041PM",
"Seg0714012505AM",
"Seg0714004152AM",
"Seg0714002843AM",
"Seg0713235444PM",
"Seg0713230241PM",
"Seg0713230030PM",
"Seg0713225825PM",
"Seg0713225548PM",
"Seg0713225028PM",
"Seg0713224159PM",
"Seg0713220356PM",
"Seg0711155346PM",
"Seg0711154018PM",
"Seg0711153432PM",
"Seg0711140748PM",
"Seg0711135636PM",
"Seg0711131412PM",
"Seg0711130857PM",
"Seg0711130157PM",
"Seg0711125338PM",
"Seg0711113158AM",
"customer",
"cmstest7",
"cmstest5",
"cmstest3",
"cmstest2",
"gffyrth",
"1testQR",
"1testgallery",
"121212"
]
}
},
{
"model": "analytics.request",
"pk": 90,
"fields": {
"intent": "GetUserAccountInformation",
"sub_intent": "",
"request_text": "what is my balance",
"response_text": "You have $111,111.11 and owe $111,111. Shall I break that down?",
"session_id": "1v69yiptamgse1niap51zr2o9x154169081480766b2d6b7-d3ce-4166-9292-c4669a3dfc14",
"user_id": "amzn1.ask.account.AHMFB2H7ZXMSCB5TLPYWCPBJGWGHFYQZ6OPPMEPQ7CT2LZXNPAFJMJELXXCCTEZ2JUE5PXRSBJHJTO3AVXT3C63AOEZLIEP3D3HIFBT5M23G4ORENFRT54AAK7I4X2HCORXJAB2UGQAHPE2TC75F2GWWZWSPO2CWEAZJJN7LJYFWEYHEJDLNQ6FSUD5LQWKBUC347K3IF32IV3I",
"device_id": "amzn1.ask.account.AHMFB2H7ZXMSCB5TLPYWCPBJGWGHFYQZ",
"device_type": "alexa",
"device_model": "NA",
"device_os": "alexa",
"elapsed_time": 2013,
"region": "NA",
"latitude": 0,
"longitude": 0,
"date": "2018-11-08T15:32:40.090+0000",
"ext_session_id": "",
"ext_user_id": "",
"score": 1,
"platform_type": "alexa",
"platform_user_id": "amzn1.ask.account.AHMFB2H7ZXMSCB5TLPYWCPBJGWGHFYQZ6OPPMEPQ7CT2LZXNPAFJMJELXXCCTEZ2JUE5PXRSBJHJTO3AVXT3C63AOEZLIEP3D3HIFBT5M23G4ORENFRT54AAK7I4X2HCORXJAB2UGQAHPE2TC75F2GWWZWSPO2CWEAZJJN7LJYFWEYHEJDLNQ6FSUD5LQWKBUC347K3IF32IV3I",
"platform_conversation_id": "amzn1.echo-api.session.8586bff8-21a5-4336-9c9f-1c261362b89d",
"registered": false,
"segment_names": [
"Test_Segment0731174425PM",
"Test_Segment0731172344PM",
"Test_Segment0731165438PM",
"Test_Segment0731164321PM",
"Test_Segment0731163349PM",
"Test_Segment0731161939PM",
"Test_Segment0731160424PM",
"Test_Segment0730160925PM",
"Test_Segment0730154627PM",
"Test_Segment0730152806PM",
"Test_Segment0730152328PM",
"Test_Segment0730150203PM",
"Test_Segment0730141720PM",
"Test_Segment0730141304PM",
"testseg",
"Tester",
"Test0730162816PM",
"Test0730162304PM",
"Test0730161031PM",
"Test0730160632PM",
"Test0730160502PM",
"Seg0730154521PM",
"Seg0730154322PM",
"Seg0730153811PM",
"Seg0730153303PM",
"Seg0716231700PM",
"Seg0716230741PM",
"Seg0715080610AM",
"Seg0715071857AM",
"Seg0715070437AM",
"Seg0715063307AM",
"Seg0715054215AM",
"Seg0715054027AM",
"Seg0715053845AM",
"Seg0715053646AM",
"Seg0715053156AM",
"Seg0715052407AM",
"Seg0715045748AM",
"Seg0714145246PM",
"Seg0714135150PM",
"Seg0714134041PM",
"Seg0714012505AM",
"Seg0714004152AM",
"Seg0714002843AM",
"Seg0713235444PM",
"Seg0713230241PM",
"Seg0713230030PM",
"Seg0713225825PM",
"Seg0713225548PM",
"Seg0713225028PM",
"Seg0713224159PM",
"Seg0713220356PM",
"Seg0711155346PM",
"Seg0711154018PM",
"Seg0711153432PM",
"Seg0711140748PM",
"Seg0711135636PM",
"Seg0711131412PM",
"Seg0711130857PM",
"Seg0711130157PM",
"Seg0711125338PM",
"Seg0711113158AM",
"customer",
"cmstest7",
"cmstest5",
"cmstest3",
"cmstest2",
"gffyrth",
"1testQR",
"1testgallery",
"121212"
]
}
},
{...},
{...},
{...}
]
and would like to extract only certain objects from it (with jq) utilizing its selectors.
Say, return only the records where .fields.user_id=="abc"
Or, return only the records where .fields.session_id=="1e2d3f"
select seems to be the way to achieve this, but I'm not sure how to express the above with it given the JSON structure above.
The following produces empty result whereas it should return records for that session_id:
curl -X GET 'http://localhost:8090/xxx/api/v1/results?dr=last5days' -H 'Cache-Control: no-cache' -H 'Postman-Token: f6b819d0-f4f6-4def-bccb-3967366779c7' -H 'secret: 5a04bfef-39eb-435a-a0d0-b274592790bb' | jq '.[] | select(.fields.session_id=="1v69yiptamgse1niap51zr2o9x154169081480766b2d6b7-d3ce-4166-9292-c4669a3dfc14")'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 21785 0 21785 0 0 272k 0 --:--:-- --:--:-- --:--:-- 272k
$
Trying different combinations with jq's entries functions which don't quite work:
curl -X GET 'http://localhost:8080/xxx/api/v1/results?dr=last5days' -H 'Cache-Control: no-cache' -H 'Postman-Token: f6b819d0-f4f6-4def-bccb-3967366779c7' -H 'secret: 5a04bf34ef-39eb-435a-a0d0-b278765790bb' | jq 'with_entries(select(.value.pk==98))'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 31755 0 31755 0 0 127k 0 --:--:-- --:--:-- --:--:-- 127k
jq: error (at <stdin>:274): Cannot use number (9) as object key
Can someone please give me a hand creating a correct jq query? TIA.
===
Trying to implement a suggestion expressed in the comments:
This jq expression:
map(select(.fields.user_id=="amzn1.ask.account.AHMFB2H7ZXMSCB5TLPYWCPBJGWGHFYQZ6OPPMEPQ7CT2LZXNPAFJMJELXXCCTEZ2JUE5PXRSBJHJTO3AVXT3C63AOEZLIEP3D3HIFBT5M23G4ORENFRT54AAK7I4X2HCORXJAB2UGQAHPE2TC75F2GWWZWSPO2CWEAZJJN7LJYFWEYHEJDLNQ6FSUD5LQWKBUC347K3IF32IV3I")) | length
seems to work in the JQ Playground (returns the correct count of 3):
but when used on the command line, it returns a wrong result (and empty array of length 0) :
$ curl -X GET 'http://localhost:8080/xxx/api/v1/results?dr=last5days' -H 'Cache-Control: no-cache' -H 'Postman-Token: f6b819d0-f4f6-4def-bccb-3967366779c7' -H 'secret: 5a04bfef-39eb-435a-a0d0-b271392790bb' | jq 'map(select(.fields.user_id=="amzn1.ask.account.AHMFB2H7ZXMSCB5TLPYWCPBJGWGHFYQZ6OPPMEPQ7CT2LZXNPAFJMJELXXCCTEZ2JUE5PXRSBJHJTO3AVXT3C63AOEZLIEP3D3HIFBT5M23G4ORENFRT54AAK7I4X2HCORXJAB2UGQAHPE2TC75F2GWWZWSPO2CWEAZJJN7LJYFWEYHEJDLNQ6FSUD5LQWKBUC347K3IF32IV3I")) | length'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 21785 0 21785 0 0 95630 0 --:--:-- --:--:-- --:--:-- 95969
0
$
What am I still doing wrong?
======
As per suggestions in comments, the following query with debug returns JSON, but still doesn't produce correct counts:
$ curl -X GET 'http://localhost:8080/xxx/api/v1/results?dr=last5days' -H 'Cache-Control: no-cache' -H 'Postman-Token: f6b819d0-f4f6-4def-bccb-3967366779c7' -H 'secret: 5a04bfef-39eb-435a-a0d0-b271392790bb' | jq ' debug | map(select(.fields.session_id=="1v69yiptamgse1niap51zr2o9x154169081480766b2d6b7-d3ce-4166-9292-c4669a3dfc14")) | length'
Using jq versions 1.6, 1.5, and 1.4, I've tested your jq program using the JSON version of the data, and all is well (on a Mac).
Please read http://stackoverflow.com/help/mcve - if you follow those guidelines, it should make debugging, communication, and/or life in general much easier for all concerned.
I'd suggest putting your jq program into a file and using the -f command-line option, at least while you're debugging this.

Parse error on Google GeoLocate API sample JSON

Has Google changed their GeoLocation api and not updated the documentation?
I have been following their example code verbatim off of the following page
https://developers.google.com/maps/documentation/geolocation/intro
I pasted the sample request into a file on my system called ex.json. I double checked that my Google Maps Geolocation API is set to on and executed the following curl command
curl -d ex.json -H "Content-Type: application/json" -i "https://www.googleapis.com/geolocation/v1/geolocate?key=[My key, yes I pasted my actual key in]"
I received the following response
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
Which according to the documentation means that there is something wrong with the example json they provided. Just for completeness the sample json looks like
{
"homeMobileCountryCode": 310,
"homeMobileNetworkCode": 260,
"radioType": "gsm",
"carrier": "T-Mobile",
"cellTowers": [
{
"cellId": 39627456,
"locationAreaCode": 40495,
"mobileCountryCode": 310,
"mobileNetworkCode": 260,
"age": 0,
"signalStrength": -95
}
],
"wifiAccessPoints": [
{
"macAddress": "01:23:45:67:89:AB",
"signalStrength": 8,
"age": 0,
"signalToNoiseRatio": -65,
"channel": 8
},
{
"macAddress": "01:23:45:67:89:AC",
"signalStrength": 4,
"age": 0
}
]
}
JsonLint verified that it is proper Json, and the documentation says that all fields are optional. What am I missing, was some required field added after the documentation was written?
Curl needs "-X POST" as extra parameter. Works like this:
curl 'https://www.googleapis.com/geolocation/v1/geolocate?key=YOURKEY' -X POST -H "Content-Type: application/json" -d #yourjsonfile.json
Found the solution, it was a silly mistake :-
my file name was "sampledata.json" i changed this to "#sampledata.json"
I tried with three different curl commands. I got response.

No JSON object could be decoded- orion context broker

I am trying out orion context broker comunication on two CentOS 6.6 machines. On the target machine I did:
./accumulator-server.py 1028 /accumulate mywebpage.lan on
And on my local machine I did:
[DevF12#localhost ~]$ (curl mywebpage.lan:1028/v1/updateContext -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' -d #- | python -mjson.tool ) <<EOF
> {
> "contextElements": [
> {
> "type": "Room",
> "isPattern": "false",
> "id": "Room2",
> "attributes": [
> {
> "name": "temperature",
> "type": "float",
> "value": "777"
> },
> {
> "name": "pressure",
> "type": "integer",
> "value": "711"
> }
> ]
> }
> ],
> "updateAction": "APPEND"
> }
> EOF
The result on the target machine is:
POST http://mywebpage.lan:1028/v1/updateContext
Content-Length: 456
User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
Host: mywebpage.lan:1028
Accept: application/json
Content-Type: application/json
{ "contextElements": [ { "type": "Room", "isPattern": "false", "id": "Room2", "attributes": [ { "name": "temperature", "type": "float", "value": "777" }, { "name": "pressure", "type": "integer", "value": "711" } ] } ], "updateAction": "APPEND"}=======================================
192.168.1.11 - - [14/Apr/2015 15:07:36] "POST /v1/updateContext HTTP/1.1" 200 -
And the message I get from the local machine is:
No JSON object could be decoded
So, what does this all mean?
1. Is the 200 code saying that it is successfully creating Room2?
2. Why am I getting the could not decode JSON then?
3. All of this brings up another question, does this mean that the weather station described in my previous post also has to run on CentOS in order to send context broker messages?
I think there is a "conceptual" misunderstanding in your test. You are sending the updateContext to 1028 which is not the port of CB (the one supposed to process updateContext messages) but the accumulator port (which purpose is process notifyContext message sent by CB as a consequence of updateContext messages, but not processing updateContext messages themselves).
Typically, Orion Context Broker runs in port 1026 by default.
Taking into account this, the specific answers are:
Is the 200 code saying that it is successfully creating Room2? No. 200 reported by accumulator just mean that the accumulator has received and acknowledge a message (any message, given that accumulator is a "dummy" application just for testing, it is not doing any real processing of that).
Why am I getting the could not decode JSON then? Try to remove | python -mjson.tool in the curl command line.
All of this brings up another question, does this mean that the weather station described in my previous post also has to run on CentOS in order to send context broker messages? Not sure about the "weather station" in your case, but if you mean the client sending updateContext to CB, it doesn't need to run in CentOS. The only requirements for the client is to be compliant with Orion API and have network connectivity to that host (and port) where Orion is listening.

Automatic job creation on jenkins using json

I want new jenkins to be created when i execute a particular job on jenkins.
I using json string to do so
following is what is used
json="{\"parameter\": [{\"name\": \"task\", \"value\": \"$task\"}], \"\": \"\"}"
url=http://xx.xx.xx.xx:8080/job/$task/build
curl -X POST $url -d token=zorn --data-urlencode json="$json"
but when i execute this i get the following error:
+ json='{"parameter": [{"name": "task", "value": "test123"}], "": ""}'
+ url=http://xx.xx.xx.xx:8080/job/test123/build
+ curl -X POST http://xx.xx.xx.xx:8080/job/soma/build -d token=zorn --data-urlencode 'json={"parameter": [{"name": "task", "value": "test123"}], "": ""}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 138 0 286k --:--:-- --:--:-- --:--:-- 286k
200 263 131 263 0 138 158k 85132 --:--:-- --:--:-- --:--:-- 122k
<html><head><title>Error 404</title></head><body bgcolor="#ffffff"><h1>Status Code: 404</h1>Exception: <br>Stacktrace: <pre>(none)
</pre><br><hr size="1" width="90%"><i>Generated by Winstone Servlet Engine v0.9.10 at Mon Aug 26 12:36:10 IST 2013</i></body></html>Notifying upstream projects of job completion
Finished: SUCCESS
Please could someone guide me as in where i am going wrong.
New job test123 does not get created.
Step1:
GET http://username:password#xx.xx.xx.xx:8080/crumbIssuer/api/json
Response:
{
"_class": "hudson.security.csrf.DefaultCrumbIssuer",
"crumb": "203a7c1e1d9c9b0accba64f41362801c",
"crumbRequestField": "Jenkins-Crumb"
}
Step2:
+ json='{"parameter": [{"name": "task", "value": "test123"}], "": ""}'
+ url=http://xx.xx.xx.xx:8080/job/test123/build
+ curl -X POST http://xx.xx.xx.xx:8080/job/soma/build -d \
token=zorn --data-urlencode \
'json={"parameter": [{"name": "task", "value": "test123"}], "": ""}' \
-H 'Jenkins-Crumb: 203a7c1e1d9c9b0accba64f41362801c'