How to use node.js Context.IO behind a department proxy? - email

Here is my node.js code to use Context.IO in a RESTful way rather than IMAP.
var ContextIO = require('contextio');
var ctxioClient = new ContextIO.Client({
key: 'MY_KEY',
secret: 'MY SECRET'
});
ctxioClient.accounts().get(function(err, res) {
if (err) throw err;
console.log(res);
});
When I executed the above code on my dormitory computer, everything worked fine. However, when I executed the code on my office computer, which is behind a departmental proxy, the code simply timed out. My department provides both http and socks proxies for internet access. The question is how to set it up in node.js?
By the way, I also tried
socksify node code.js
It did not time out. Instead, it just did not response.

Related

Testing feathers socket

I have hardly done anything with feathers sockets so far and therefore I need your help.
I have written a test which tests the functionality of my websocket to move users into the right channels. To do this I created two socketIo-clients in my test and let them connect to the websocket with the help of my own helpers, which also do the authentication when the connection is established.
If I run the test on its own, it will work fine. But once I run all the tests together, the test no longer works, because the SocketIo-Clients can not established any connection. This can be noticed, because no connection event is triggered at the server.
In my Test I do:
before((done) => {
server = app.listen(app.get('port'), done);
socketUrl = 'ws://localhost:5555}/';
});
socket = io(socketUrl);
and
after(async () => {
await server.close();
});
I found out, that any test, which is also doing server = app.listen(app.get('port'), done); before the socket test, will cause the socket test to fail. Can it be possible, that await server.close(); does not really close the http-server and/or the ws-server?

Connecting Aurelia with backend API

Context: I'm starting a new project for my company. It's been many years since I've done some web development and decided to build it using the latest platforms (so I'm a still new to all of this).
Current stack:
Aurelia frontend (running on localhost:9000)
Backend REST API using ExpressJS (running on localhost:8000)
PostGreSQL database running on AWS, providing data for the backend
Question: I can't seem to connect my frontend with my backend properly.
Here is my code:
import {inject} from "aurelia-framework";
import {HttpClient} from "aurelia-http-client";
#inject(HttpClient)
export class Login {
constructor(httpClient){
this.http = httpClient;
}
signIn() {
const url = 'http://localhost:8000/api/user/demo/test';
this.http
.get(url)
.then(data => {
console.log("data");
console.log(data);
})
.catch(error => {
console.log('Error getting ' + url);
console.log(error);
});
};
}
This always end up in the catch block, with a "response: ProgressEvent"
If I put the url in the browser I get a proper JSON:
{"status":"success","data":[],"message":"Retrieved ALL users"}
The code above only works for 'local' content, i.e. localhost:9000. As soon as I need content from somewhere else I get this error. What am I missing?
I think that CORS is not allowing you to access localhost:8000 from localhost:9000. To solve this, you should enable your ExpressJS server to accept CORS requests from localhost:9000 (or all hosts using a wildcard "*").
Look into these resources:
https://enable-cors.org/server_expressjs.html
https://github.com/expressjs/cors
Or search Google for 'expressJS cors'.

production build of ember app works, but when using ember serve, cookies not sent to api

I have a rest API running on localhost:8001/my_app/api/, and I have apache setup to reverse proxy it from localhost/my_app/api. That's working fine.
In order to have permissions to do anything with the api, it requires my session cookie, my csrftoken cookie and a X-CSRFToken HTTP header. I've configured adapters/application.js as follows:
adapters/application.js
import Ember from 'ember';
import DRFAdapter from './drf';
export default DRFAdapter.extend({
headers: Ember.computed(function() {
return {
'X-CSRFToken': Ember.get(document.cookie.match(/csrftoken\=([^;]*)/), '1'),
};
}).volatile(),
ajax: function(url, method, hash) {
hash = hash || {}; // hash may be undefined
hash.crossDomain = true;
hash.xhrFields = {withCredentials: true};
return this._super(url, method, hash);
}
});
If I do a ember build -prod and copy the contents of the dist dir to /var/www/myApp/, apache serves my app, and it works just fine.
It's when I try to use ember-cli's builtin development server where I run into problems. I'm getting 403 errors from my api. It turns out that while the X-CSRFToken header is being sent neither of my cookies are. If I look in my chrome developer tools, it shows that I have both cookies - they simply aren't in the request headers. They're both from localhost, so I'm a bit confused.
Also, I currently I have CORS on my rest backend setup. Here are the headers I'm currently receiving:
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://localhost:4200
I thought that since allow-credentials == true and allow-origin != * that cookies were supposed to be allowed. sigh.
Here's my API_HOST and contentSecurityPolicy:
config/environment.js
if (environment === 'development') {
ENV.APP.LOG_TRANSITIONS = true;
ENV.APP.API_HOST = "http://localhost"
ENV.contentSecurityPolicy = {
'default-src': "'none'",
'script-src': "'self' 'unsafe-eval' localhost",
'font-src': "'self'",
'connect-src': "'self' localhost",
'img-src': "'self'",
'style-src': "'self'",
'media-src': "'self'"
};
}
As you can see above, the api requests are being sent through my reverse proxy. I've played around with ember serve --proxy trying both http://localhost:80/ and http://localhost:8001/ but neither have helped. I've also tried setting my development ENV.API_HOST = 'http://localhost:8001/'; with and without the various proxy values.
This edit, build, deploy, refresh my browser, test, & repeat process is REALLY slow and getting old REALLY fast.
Could someone please explain to me how to get the ember-cli development server to properly access my rest api?

How can I send emails using my own mail server in Meteor?

I am trying to enable email support for my Meteor application, and since I have my own server I want to also use my own mail server. So I installed postfix in my Debian wheezy server and successfully sent and email to my GMail address, so that means the mail server works properly and sends emails.
When I deploy my Meteor app and try to send an email though, say to do a password reset, my app crashes with the following error:
Exception while invoking method 'forgotPassword' RecipientError: Can't send mail - all recipients were rejected
at Object.Future.wait (/home/loupax/phial/bundle/programs/server/node_modules/fibers/future.js:326:15)
at smtpSend (packages/email/email.js:94)
at Object.Email.send (packages/email/email.js:155)
...
...
My MAIL_URL environment variable is in the format MAIL_URL=smtp://my_domain.tld.
Looks like all I had to do, is change the MAIL_URL environmental variable from smtp://my_domain.tld to smtp://localhost. After that everything worked just fine
Is your server on Amazon? Sometimes SMTP servers are known to block anything sent from certain hosting providers entire IP ranges to block spam.
You might want to consider using a different SMTP server, Amazon's SES, or Mandrill (which has a meteorite package to help) (personally I use both SES and Mandrill).
Note its not only Amazons IP blocks which are in this, its also any hosting provider a spammer can quickly set up. Your SMTP sever probably employs a list from somewhere with all these ips on it
for forgot password email, follow below steps
1) create smtp.js file in server folder and past below code in it
Meteor.startup(function () {
process.env.MAIL_URL =
'smtps://abcd#gmail.com:password#smtp.gmail.com:465';
});
2) paste below code in forgot password.js file
Template.forgot.events({
'click #forgot'(event,template) {
event.preventDefault();
let email = $("#email").val();
// paste below code in server.main.js -> in Meteor.startup function.
/* Accounts.urls.resetPassword = function(token) {
return Meteor.absoluteUrl('reset-password/' + token);
};*/
Accounts.forgotPassword({email:email},function (error,result) {
if(error)
{
alert(error);
}
else
{
console.log(result);
alert("mail sent ..!! Check your mail box");
FlowRouter.go('/login');
}
});
}
});
3 ) in main.js file in server folder paste below code
import '../server/smtp';
Meteor.startup(() => {
// code to run on server at startup
Accounts.urls.resetPassword = function(token) {
return Meteor.absoluteUrl('reset-password/' + token);
};
});
check your mail

SASL authorization failing while connecting to XMPP server

I am trying to connect to gmail using SMACK API through XMPP server. but getting the
error : SASL authentication failed using mechanism PLAIN
you can check a glimpse of code. I got it from net only
ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
connection = new XMPPConnection(connConfig);
connection.connect();
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
I checked in the smack debug window. it says in XML :
< invalid-authzid />
I am already having account on gmail and my gtalk is also running.
You need to set the authentication before you connect viz
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
must appear before connection.connect().
See my blog.
ConnectionConfiguration cc = new ConnectionConfiguration(
"vietnam.agilemobile.com", 5222, vietnam.agilemobile.com");
XMPPConnection connection = new XMPPConnection(cc);
try {
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
connection.connect();
Log.e("LOGIN", "" + 111);
// You have to put this code before you login
Log.e("LOGIN", "" + 222);
// You have to specify your gmail addres WITH #gmail.com at the end
connection.login("nemodo", "123456", "resource");
Log.e("LOGIN", "" + 333);
// See if you are authenticated
System.out.println(connection.isAuthenticated());
} catch (XMPPException e1) {
e1.printStackTrace();
}
I also get this mistake, but i can not work.
For anyone looking for possible solutions to this many years after this was originally asked and answered, I recently was able to get past this authentication error by explicitly setting the authzid value on the XMPPTCPConnectionConfiguration.
I was running into an issue where my connection configuration worked fine for some client XMPP servers, but not for others, even though they were all using SASL PLAIN authentication. After some troubleshooting, I learned that the ones that were failing were expecting an authzid value. After adjusting my code to set this, it works in both the environments that were working before, as well as the environments that were failing.
Here is how I am building my connection configuration:
XMPPTCPConnectionConfiguration.builder()
.setHost(XMPP_DOMAIN)
.setXmppDomain(XMPP_DOMAIN)
.setPort(XMPP_PORT)
.setCompressionEnabled(true) // optional, not all servers will support this
.setUsernameAndPassword(XMPP_USER, XMPP_PASSWORD)
.setResource(XMPP_RESOURCE)
.setAuthzid(JidCreate.entityBareFrom(String.format("%s#%s", XMPP_USER, XMPP_DOMAIN))) // <-- this was the change I needed
.build();
Specifically I needed to add this line:
.setAuthzid(JidCreate.entityBareFrom(String.format("%s#%s", XMPP_USER, XMPP_DOMAIN)))