opentok interconnect with node js express - node.js

I am implementing opentok interconnect with nodejs express.
Getting error:
No callback given to dial, while implementing dial-out.
My use case is as per documentation.
I am able to get all required values like config, sessionId, token, auth. , but still unable to connect the call.
opentok.dial(sessionId, token, config.uri, options, {
auth: {
username: config.uname, password: config.pass }
},
function (err, sipCall) {
if (err)
return res.status(500).send('Platform error starting SIP Call:'+err);
res.send(sipCall);
});

It looks like you are posting too many arguments into the function before the callback.
From the github repo we can see the example:
opentok.dial(sessionId, token, sipUri, options, function (error, sipCall) {
We can see the arguments:
sessionId
token
sipUri
options
callback
You however are passing in an object between options and the callback.
opentok.dial(sessionId, token, config.uri, options,
// Extra object argument, is this meant to be options?
{
auth: {
username: config.uname, password: config.pass}
},
function (err, sipCall) {
if (err)
return res.status(500).send('Platform error starting SIP
Call:'+err);
res.send(sipCall);
});

Related

nodejs gmail api not supporting promises

Google recommends using promises, but its code examples do not, and I'm struggling to make the gmail api work with promises when I modify the code from the online docs.
All I've changed are the lines below, but I get an error
VM677:5 Uncaught TypeError: gmail.users.messages.list(...).then is not a function
gmail.users.messages.list({
auth: auth,
userId: 'me',
labelIds: 'Label_14'
// }, function(err, response) {
// if (err) {
// console.log('The API returned an error: ' + err);
// return;
// }
// console.log(response);
})
.then(response => {
console.log("success", response);
})
Most of the examples of SO use promises so I think it should be possible but I can't see what the problem is. Would really welcome some help
The googleapis module does not support promises.
Consider using util.promisify if you want to use promises with this module.
var list = util.promisify(gmail.users.messages.list);
list({
auth: auth,
userId: 'me',
labelIds: 'Label_14'
})
.then(...);

Nodejs NTLM/Basic auth in SOAP

I try to connect nodeJs with soap service, using SOAP package.
In server I have a basic authentification.
How I can put basic authentification in soap library? I have this code:
soap.createClient(url, function(err, client) {
console.log(err)
});
in the log err, I receive the 401 page (for not auth). In web page of SOAP package I see this method:
client.setSecurity(new soap.BasicAuthSecurity('user', 'pass'));
Where I need to put this code? the reicevied client inside createClient are undefined.
EXTRA: The ideal was I can auth using NTLM, it's posible? I have a node app inside the same machine than soap server.
EDIT
I try to set NTLM credentials with soap-ntlm-2 library, using this code:
var url = "http://server/instance/ReportService2010.asmx";
var options = {
wsdl_options: {
ntlm: true,
username: "RSUser",
password: "Reporting2012",
workstation: "",
domain: ""
}
};
soap.createClient(url, options, function (err, client, body) {
if (err) {
console.log(err);
}
// normal use
//client.setSecurity(new soap.NtlmSecurity(options.wsdl_options.userName, options.wsdl_options.password, options.wsdl_options.domain, options.wsdl_options.workstation));
// or object can be passed
client.setSecurity(new soap.NtlmSecurity(options.wsdl_options));
console.log(client.describe());
report = client.ReportingService2010.ReportingService2010Soap;
});
But I have the same error massage: client is undefined.

Not getting user information with Google Plus sign-in api + Node.js

I have the following code snippet, to retrieve user information when he uses gmail to login:
oauth2Client.getToken(code, function(err, tokens) {
if (err) {
console.log(err);
res.send(err);
return;
}
console.log("allright!!!!");
var plus = google.plus('v1');
var API_KEY = 'AXXXXXXXXXXXXXXXXXXXXXXXXXU'; // specify your API key here
plus.people.get({
auth: API_KEY,
userId: 'me'
}, function (err, user) {
console.log(user);
});
res.send(tokens);
});
Gmail and google+ APIs are both enabled. The user object which is retrieved is returning 'null', while it should return the user information object. Why is this so? Am i giving correct value for userId? How can i retrieve information like gmail address, first name, last name, etc.
It seems you are using the client wrong, here you have an example taken from the Node.js client repo:
oauth2Client.setCredentials({
access_token: 'ACCESS TOKEN HERE',
refresh_token: 'REFRESH TOKEN HERE'
});
plus.people.get({
userId: 'me',
auth: oauth2Client
}, function (err, response) {
// handle err and response
});
You have to pass the oauth2Client instance through the auth property, not API_KEY.
Did you check the err argument? I guess you are getting null because it is returning an error, something like you did not authenticate.

Does the Gmail API support JWT?

I want to access the Gmail API using NodeJS.
I'm using a server-to-server approach (see this) but when I execute the code below, I get a backEndError, code 500 from the Google API.
Any ideas?
var authClient = new google.auth.JWT(
'email',
'key.pem',
// Contents of private_key.pem if you want to load the pem file yourself
// (do not use the path parameter above if using this param)
'key',
// Scopes can be specified either as an array or as a single, space-delimited string
['https://www.googleapis.com/auth/gmail.readonly']
);
authClient.authorize(function(err, tokens) {
if (err)
console.log(err);
gmail.users.messages.list({ userId: 'me', auth: authClient }, function(err, resp) {
// handle err and response
if (err) {
console.log(err);
});
Yes, I have the same problem. If I use the scope "https://mail.google.com", I get
403
{
"error" : "access_denied",
"error_description" : "Requested client not authorized."
}
And if I use the scope "https://mail.google.com/" (notice the / at the end), I get
403
'Forbidden'
It seems to be related to using JWT and service account.

Node.js twitter auth redirect

I want to enable oauth login with twitter.
I added the following code for everyauth in server.js
everyauth
.twitter
.consumerKey('mykey')
.consumerSecret('mysecret')
.findOrCreateUser(function (sess, accessToken, accessSecret, twitUser) {
return usersByTwitId[twitUser.id] || (usersByTwitId[twitUser.id] = addUser('twitter', twitUser));
})
.redirectPath('/about');
where 'mykey' and 'mysecret' are the correspoding of my twitter app.
The settings in my twitter app are:
Access level: Read and write
About the application permission model
Consumer key: mykey
Consumer secret: mysecret
Request token URL: https://api.twitter.com/oauth/request_token
Authorize URL: https://api.twitter.com/oauth/authorize
Access token URL: https://api.twitter.com/oauth/access_token
Callback URL: http://192.168.1.197:8002/
Sign in with Twitter: Yes
The problem is after correct loging, the web stays in 'https://api.twitter.com/oauth/authenticate' and doesn't redirect to my callback url
What could be wrong?
UPDATE:
now I'm getting one of the following errors...
{"errors": [{"message": "The Twitter REST API v1 is no longer active.
Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.", "code": 68}]}
I really don't know how to update to version 1.1. I tried some solutions from the dev twitter forum but nothing.
500 Error: Step rememberTokenSecret of `twitter` is promising:
requestTokenSecret ; however, the step returns nothing.
Fix the step by returning the expected values OR by returning a Promise
that promises said values.
MORE INFO
I updated everyauth and twitter api. I check the file twitter.js in the everyauth's node_module folder
...
.fetchOAuthUser( function (accessToken, accessTokenSecret, params) {
var promise = this.Promise();
this.oauth.get(this.apiHost() + '/1.1/users/show.json?user_id=' + params.user_id, accessToken, accessTokenSecret, function (err, data, res) {
if (err) {
err.extra = {data: data, res: res};
return promise.fail(err);
}
var oauthUser = JSON.parse(data);
promise.fulfill(oauthUser);
});
return promise;
})
...
Thank you.

Resources