PayPal Client Authentication Failed - node.js

Since I switched from the sandbox mode to the real deal I get a client authentication failed error.
Config:
{
"port": 5000,
"api": {
"host": "api.paypal.com/v1/",
"port": "",
"client_id": "-",
"client_secret": "-"
}
}
I've double checked my client id and secret, they are enabled and aren't for the sandbox mode.
Code:
paypalService.getPaypalMethodOption(req.body.paymentMethodOptionId).then(function (paymentMethodOption) {
var invoiceId = uuid.v4();
var payment = {
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"transactions": [{
"amount": {
"currency": 'USD',
"total": paymentMethodOption.Price
},
"description": paymentMethodOption.Description,
"invoice_number": invoiceId
}]
};
payment.payer.payment_method = 'paypal';
payment.redirect_urls = {
"return_url": "http://localhost:3000/paypal/execute",
"cancel_url": "http://localhost:3000/donate/cancelled"
};
paypal.payment.create(payment, function (error, payment) {
// error
});
});
What can be the problem?

After searching for a few hours i found out that i needed another property.
Apparently you need to add the property mode with the value "live". The documentation isn't very clear on this part, neither are there any live example codes in the node sdk github repository.
My config now looks like the following:
{
"port": 5000,
"api": {
"mode": "live",
"host": "api.paypal.com",
"port": "",
"client_id": "-",
"client_secret": "-"
}
}

Related

Mongo client in Node doesn't receive connection response

I currently have a set of nodejs modules (containers) that connect to a local mongodb (also a container).
All modules works perfectly but with one of the I have the following problem:
https://i.stack.imgur.com/xuFqw.png
The connection seems to be accepted by mongo but the client doesn't receive the response and keeps waiting until it times out after 30 second (watch timestamps in the log)
The code of the client is the following:
async function connectToMongo() {
try {
const mongoUrl = 'mongodb://mongo:27017/LocalDB'
let result = await MongoClient.connect(mongoUrl, { useUnifiedTopology: true })
logger.info("Connected to Mongo DB")
return result
} catch (err) {
logger.error("Cannot connect to Mongo - " + err)
throw err
}
}
And is exactly the same as the other modules (that works).
Mongo is started without any settings or authentication.
I have tried using the following hostnames:
mongo : name of the container in which mongo is running
host.docker.internal : to address the host since the 27017 port of the container is binded to the host port
I honestly don't know what to try anymore...does anybody have an idea about what could be the problem?
UPDATE: as requested i'm adding info about how i'm starting the containers. Anyway I have omitted this part because they are started as Azure IoT Edge Modules. Anyway here is the infos from the deployment template:
"modules": {
"mongo": {
"settings": {
"image": "mongodb:0.0.1-replset-noauth",
"createOptions": "{\"HostConfig\":
{\"PortBindings\":{\"27017/tcp\":[{\"HostPort\":\"27017\"}]}}}"
},
"type": "docker",
"version": "1.0",
"status": "running",
"restartPolicy": "always"
},
"healthcheck": {
"settings": {
"image": "${MODULES.HealthCheck.debug}",
"createOptions": {
"HostConfig": {
"PortBindings": {
"9229/tcp": [
{
"HostPort": "9233"
}
]
}
}
}
},
"type": "docker",
"version": "1.0",
"env": {
"MONGO_CONTAINER_NAME": {
"value": "mongo"
},
"MONGO_SERVER_PORT": {
"value": "27017"
},
"DB_NAME": {
"value": "LocalDB"
}
},
"status": "running",
"restartPolicy": "always"
}
},
While this is the configuration of another module that perfectly works:
"shovel": {
"settings": {
"image": "${MODULES.Shovel.debug}",
"createOptions": {
"HostConfig": {
"PortBindings": {
"9229/tcp": [
{
"HostPort": "9229"
}
]
}
}
}
},
"type": "docker",
"version": "1.0",
"env": {
"MONGO_CONTAINER_NAME": {
"value": "mongo"
},
"MONGO_SERVER_PORT": {
"value": "27017"
},
"DB_NAME": {
"value": "LocalDB"
}
},
"status": "running",
"restartPolicy": "always"
},
(it's basically the same)
The modules are currently being launched using the IoT Simulator or on an IoT Edge device as Single Device deployments.

How to implement CameraStream traits through Google local home sdk

We tried the local sdk and handled the SYNC response with otherDeviceIds.
The scan config should be ok because our local app already received the IDENTITY request with with expected udp payload.
The IDENTITY response should be ok, because the local platform should already passed check the "verificationId", becasuse if I set the verificationId to some string else it says not passed verification.
The problem is when I tried "show the camera", the local fulfilment execute callback function not triggered. In this situation, my firebase cloud funtion still received the "action.devices.commands.GetCameraStream" command.
I tried the lamp straits sampleļ¼Œ it looks like it works well.
Anyone knowns if the Google local Home sdk support CameraStream traits or NOT.
The following log is the object returned by SYNC in our firebase cloud function, we add "otherDeviceIds": [{"deviceId": "789"}] field,
in order to complete the local sdk.
SYNC JSON object:
{
"requestId": "465812xxx029114126",
"payload": {
"agentUserId": "023XXXXd4d850c01cd16ebb636eb8418",
"devices": [{
"id": "123",
"traits": ["action.devices.traits.CameraStream"],
"name": {
"defaultNames": ["xxx CAMERA"],
"nicknames": ["Front door"],
"name": "Camera"
},
"customData": {
"fooValue": 88,
"barValue": true,
"bazValue": "string"
},
"attributes": {
"cameraStreamSupportedProtocols": ["hls"],
"cameraStreamNeedAuthToken": false,
"cameraStreamNeedDrmEncryption": false
},
"otherDeviceIds": [{
"deviceId": "789"
}],
"type": "action.devices.types.CAMERA",
"willReportState": false
}]
}
}
The IDENTITY response should be ok, because the local platform should already passed check the "verificationId".
IDENTIFY request object(Local SDK):
{
"requestId": "XXXXXA5FB895B0CD58C022BDC",
"inputs": [{
"intent": "action.devices.IDENTIFY",
"payload": {
"device": {
"udpScanData": {
"data": "A562696463373839656D6F64656C6966616B6563616E64796668775F726576656576742D316666775F7265766776312D62657461686368616E6E656C738101"
}
},
"structureData": {}
}
}],
"devices": [{
"id": "123",
"customData": {
"barValue": true,
"bazValue": "string",
"fooValue": 88
}
}]
}
IDENTIFY response object(Local SDK):
{
"intent": "action.devices.IDENTIFY",
"requestId": "XXXXX8D0A4A5FB895B0CD58C022BDC",
"payload": {
"device": {
"id": "",
"verificationId": "789"
}
}
}
But when I tried "show the camera", the local fulfilment execute callback function not triggered.
In this situation,my firebase cloud funtion still received the "action.devices.commands.GetCameraStream" command.
Below is the log when I say "show the camera" my firebase cloud funtion.
{
"inputs": [{
"context": {
"locale_country": "US",
"locale_language": "en"
},
"intent": "action.devices.EXECUTE",
"payload": {
"commands": [{
"devices": [{
"customData": {
"barValue": true,
"bazValue": "string",
"fooValue": 88
},
"id": "123"
}],
"execution": [{
"command": "action.devices.commands.GetCameraStream",
"params": {
"StreamToChromecast": true,
"SupportedStreamProtocols": ["progressive_mp4", "hls", "dash", "smooth_stream"]
}
}]
}]
}
}],
"requestId": "xxxx366353358387"
}
CameraStream is not currently supported by local fulfillment.

Loopback Email Connector not sending emails

I have a Loopback Application with a REST API.
I want to make a REST API Enpoint /Email/sendEmail which sends an email. I did this tutorial: https://loopback.io/doc/en/lb3/Email-connector.html, but it's not working for me somehow.
When I open https://localhost:3000/explorer , I can see the API Endpoint and I can press the button "Try it out". But then it just loads forever and after a while I get a Timeout error in the console.
File: datasource.json
{
"db": {
"host": "localhost",
"port": 27017,
"url": "",
"database": "siemens",
"password": "",
"name": "db",
"user": "",
"useNewUrlParser": true,
"connector": "mongodb"
},
"email": {
"name": "email",
"connector": "mail",
"transports": [{
"type": "SMTP",
"host": "smtp.gmail.com",
"secure": true,
"port": 465,
"auth": {
"user": "xbit.dany#gmail.com",
"pass": "XXX"
}
}]
}
}
File: model-config.json
"Email": {
"dataSource": "email",
"public": true
}
File: email.js
module.exports = function(Email) {
// send an email
Email.sendEmail = function(cb) {
console.log("Sending Email");
Email.app.models.Email.send({
to: 'siemens.dany#gmail.com',
from: 'xbit.dany#gmail.com',
subject: 'my subject',
text: 'my text',
html: 'my <em>html</em>'
}, function(err, mail) {
console.log('email sent!');
cb(err);
});
}
Email.remoteMethod(
'sendEmail', {
http: {
path: '/sendEmail',
verb: 'get'
},
returns: {
}
}
);
};
File: models/email.json
{
"name": "Email",
"base": "Model",
"properties": {
"to": {"type": "String", "required": true},
"from": {"type": "String", "required": true},
"subject": {"type": "String", "required": true},
"text": {"type": "String"},
"html": {"type": "String"}
}
}
The mail is now working. This is the code of email.js
module.exports = function(emailDS) {
// send an email
emailDS.sendEmail = function(cb) {
console.log("Sending Email");
emailDS.app.models.Email.send({
to: 'siemens.dany#gmail.com',
from: 'xbit.dany#gmail.com',
subject: 'my subject',
html: 'my <em>html</em>'
}, function(err, mail) {
console.log("Mail: " + mail);
console.log("Error: " + err);
cb(null, mail);
});
}
emailDS.remoteMethod(
'sendEmail', {
http: {
path: '/sendEmail',
verb: 'get'
},
returns: {
arg: 'Status', type:'string'
}
}
);
};

New to Node and having trouble with the Youtube Data API

Using Node.js for the first time and working with the Youtube Data API. I can't quite get the data I want from the API when I make a request to it. This is what the data coming back from the API is supposed to look like:
/**
* API response
*/
{
"kind": "youtube#commentThreadListResponse",
"etag": "\"VPWTmrH7dFmi4s1RqrK4tLejnRI/yVL3QyyDwJFkFNOcCd4KZCcTFDw\"",
"nextPageToken": "QURTSl9pMlQySG1zcHRKb0dNZ3dWdlYtcUhyRDFDVlJXaHFmdVFiMUlaUFJfTTNjdTFpQzFNWUNuWjhBY0d2ZV8tTGR2aHFXRXRJVDZRQVpRM0YzNndWVXlQVFNwOU94UVFCWVd2empIVUlGdHlFR25keU8=",
"pageInfo": {
"totalResults": 20,
"resultsPerPage": 20
},
"items": [
{
"kind": "youtube#commentThread",
"etag": "\"VPWTmrH7dFmi4s1RqrK4tLejnRI/OqxtT8nFAjcFFrHa4DbZrY_NItM\"",
"id": "z13bwzmokuzcxtcqn04cclqbiozixldh21o"
},
{
"kind": "youtube#commentThread",
"etag": "\"VPWTmrH7dFmi4s1RqrK4tLejnRI/1B_usKd_ZpCLxG5l5nL7QfUtG3o\"",
"id": "z13puhijunbzytdcn22lstwptmybyzwdl"
},
{
"kind": "youtube#commentThread",
"etag": "\"VPWTmrH7dFmi4s1RqrK4tLejnRI/h8sS5KTOFa7CQWU5Je2Fp5UQ0bk\"",
"id": "z13dfbwzjyrpiznqc04cgjlpbyn0wtaiqpw0k"
},
{
"kind": "youtube#commentThread",
"etag": "\"VPWTmrH7dFmi4s1RqrK4tLejnRI/FQEl6XU95FHiM1ijRxC5fqngmqk\"",
"id": "z12atro51wfhzvmp104cihfytveyshbr4s40k"
},
{ ...........AND SO ON
I then use the following code in an attempt to console.log() this data from the youtube API
var DATABASE = youtube.commentThreads.list(
{ 'videoId': '7YcW25PHnAA', 'part': 'id, replies'}, function(err, data){
if(err){
console.error('Error: ' + err);
}
});
var resp = JSON.stringify(DATABASE);
console.log(resp);
But this is my output instead:
{
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "www.googleapis.com",
"port": null,
"hostname": "www.googleapis.com",
"hash": null,
"search": "?videoId=7YcW25PHnAA&part=id%2C%20replies&key=AIzaSyDTTnj4HncXQCM3U-9XUvHyIf7kE9f2ZUk",
"query": "videoId=7YcW25PHnAA&part=id%2C%20replies&key=AIzaSyDTTnj4HncXQCM3U-9XUvHyIf7kE9f2ZUk",
"pathname": "/youtube/v3/commentThreads",
"path": "/youtube/v3/commentThreads?videoId=7YcW25PHnAA&part=id%2C%20replies&key=AIzaSyDTTnj4HncXQCM3U-9XUvHyIf7kE9f2ZUk",
"href": "https://www.googleapis.com/youtube/v3/commentThreads?videoId=7YcW25PHnAA&part=id%2C%20replies&key=AIzaSyDTTnj4HncXQCM3U-9XUvHyIf7kE9f2ZUk"
},
"method": "GET",
"headers": {
"User-Agent": "google-api-nodejs-client/0.10.0",
"host": "www.googleapis.com",
"accept": "application/json"
}

Can AWS Cognito adminCreateUser send a temporary password?

The Amazon Cognito adminCreateUser documentation on TemporaryPassword states:
This parameter is not required. If you do not specify a value, Amazon
Cognito generates one for you.
How does the user ever get it? At first I thought it would get emailed to the user, but that doesn't seem to be the case. Then I thought maybe it would come back in the response. Nope.
Here's the code I'm calling in my node JS Lambda function:
adminCreateUser(
{
"UserPoolId": "us-east-1_XXXXXXXX",
"Username": "roger__mailinator.com",
"DesiredDeliveryMediums": [
"EMAIL"
],
"ForceAliasCreation": false,
"MessageAction": "SUPPRESS",
"UserAttributes": [
{
"Name": "given_name",
"Value": "Rodger"
},
{
"Name": "family_name",
"Value": "Ribbit"
},
{
"Name": "name",
"Value": "Rodger Ribbit"
},
{
"Name": "email",
"Value": "roger#mailinator.com"
},
{
"Name": "custom:title",
"Value": "Animation Designer"
},
{
"Name": "custom:company",
"Value": "76"
}
]
}, function(error, data) {
if (error) {
console.log("Error adding user to cognito: " + error, error.stack);
//...
} else {
console.log("Received back from cognito: " + JSON.stringify(data));
//...
}
});
and here's the response I get:
Received back from cognito:
{
"User": {
"Username": "roger__mailinator.com",
"Attributes": [
{
"Name": "custom:title",
"Value": "Animation Designer"
},
{
"Name": "sub",
"Value": "1cd612a0-0da0-4e7b-84c7-30570fab80a9"
},
{
"Name": "name",
"Value": "Rodger Ribbit"
},
{
"Name": "given_name",
"Value": "Rodger"
},
{
"Name": "family_name",
"Value": "Ribbit"
},
{
"Name": "email",
"Value": "roger#mailinator.com"
},
{
"Name": "custom:company",
"Value": "76"
}
],
"UserCreateDate": "2017-03-30T18:31:34.283Z",
"UserLastModifiedDate": "2017-03-30T18:31:34.283Z",
"Enabled": true,
"UserStatus": "FORCE_CHANGE_PASSWORD"
}
}
Where does the password go? Are we supposed to guess it? :-)
I think it's because you are passing "MessageAction": "SUPPRESS". That would suppress the sending of the email.
The temporary password is emailed to the user and he needs to reset it upon the first login.
The answer is that the user email needs to be verified before they'll receive it. So you need to modify the user attribute on email to be verified. See: https://stackoverflow.com/a/43033722/491553

Resources