Get windows client username in Nodejs - node.js

I am developing a little application in nodeJS and AngularJS. all my clients are windows machines, and they are all in the same domain.
I want to add some text label in the page like " Welcome ! USERNAME" .
how can get the Windows username of the client when he gets homepage?
I read about passport and node-sspi, but didnt understand how to implement that.
thank you :)

Stackoverflow user 'azium', explains in this response that
"AngularJS is a client side application and only has access to the
variables that are delcared (sic) in the browser's window object. The
Environment object is something that is only accessible on the server
by default."
However, according to Arhsim Tima you can try the following javascript,
For IE:
var objUserInfo = new ActiveXObject("WScript.network");
document.write(objUserInfo.ComputerName+"<br>");
document.write(objUserInfo.UserDomain+"<br>");
document.write(objUserInfo.UserName+"<br>");
var uname = objUserInfo.UserName;
alert(uname);
For Firefox:
function getUser() {
return Components.classes["#mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment).get('USERNAME');
}

Related

Can I access twitter auth data via firebase cloud functions Admin SDK? If so, how?

I'm currently using firebase for the backend of a project I'm working on. In this project, the client authenticates using the firebase-twitter sign in method. For the purpose of security, I'm trying to minimise the amount of communication between the client and backend when it comes to auth data. In jest of this, I'm wondering if there is a way to access the auth data i.e. the user's twitter key/secret (as well as things like the user's twitter handle) from the server-side after the user authenticates ? I figured there might be a way as the authentication happens through twitter + firebase, but I'm struggling to find the exact solution I need in the documentation (been stuck on this for a week now) so was hoping someone else already knows if this is possible and how :) cheers
Maybe not the best way, but you can try: on client side use RealTime database and add a new entry every time the user log in. They call this 'realtime triggers'.
You don't mention what front are you using, but on ionic is something like:
firebase.auth().onAuthStateChanged(function(user) {
if (user)
this.db.addLogin(user.uid)
});
On database class function:
addLogin(uid){
let path = "/logins/"
let ref = this.db.list(path)
let body = {uid: uid}
return ref.push(body)
}
On the server side, listen the path using child_added
var ref = db.ref("logins");
ref.on("child_added", function(snapshot, prevChildKey) {
var newPost = snapshot.val();
console.log("Uid: " + newPost.uid);
console.log("Previous Post ID: " + prevChildKey);
});
More information about triggers

Connect manually with sails.io.js

I'm trying to use sails.io.js in a chrome extension.
I'm setting manually the url of my sails server with the line :
io.sails.url = "http://localhost:1337";
But I would like to get the url from the chrome local storage (to save the url not directly in the code). But the problem is, as said here:
You get 1 clock tick after the import before the socket attempts to
connect.
So if I get the URL from the chrome local storage with :
storage.get('url', function(result){
var url = result.url;
io.sails.url = url ;
});
It's too late! The options must be set just after the sails.io.js code..
So I was thinking about disabling autoConnect with :
io.sails.autoConnect = false;
(As said there)
But now my question is : How can I can connect manually with io.sails ?
I've tried io.sails.connect(), did not work. Any ideas ?
Thank you very much,
Well, it's yours to customize but if you want to get away with minimal amount of changes to sails.io.js then you could
change setTimeout to io.sails.doit = function() {
throw away the io.sails.autoConnect check
call io.sails.doit(..) when you're ready
Also, if you want to pass something over during the handshake you can add {'query':'param='+value} as second argument to io.connect(io.sails.url);
It is then available in sails app's config/sockets.js through socket.handshake.query.param.

How can I access to my nodeJS app in console on my server?

I have an application nodeJS started like a deamon with forever(https://github.com/nodejitsu/forever).
So now, how can I access to my app and be abble to watch and change values of variables with SSH connexion on my server?
How open console on my app without interuption of service?
thx.
You should give node-inspector a look.
There's nothing built-in for that.
However, you can create a function on the server that will eval whatever string you put as parameter.
To query that function, you can use ajax or socket.io for example.
Socket.io example
socket.on('evalStr', function (str) { eval(str);}); //server
socket.emit('evalStr', "myVar = 10;"); //client via console
Edit: Of course, you can add security such as testing a password before evaluating.

Generate node-xmpp script for browser

I am developing an application on php. I need a chat on xmpp nodejs. Sending a message will go from web page.
I found enter link description here. In terminal everything works fine. But how do I attach client script to the browser?
I generate script by:browserify node_modules/node-xmpp/lib/node-xmpp-browserify.js > nodeXmpp.js and attach it to web page:
Then trying to use it:
$(document).ready(funcrion(){
var client = new XMPP.Client({
jid: 'user#example.com',
password: 'password'
});
});
And chrome console telling me:
Cannot load StringPrep-0.2.3 bindings (using fallback). You may need to npm install node-stringprep nodeXmpp.js:3669
event.returnValue is deprecated. Please use the standard event.preventDefault() instead. jquery.js:3254
Uncaught TypeError: Object # has no method 'resolveSrv'
Object # - its "dns".
And before generate script i install node-stringprep.
Question is how build xmpp client script for browser.
You didn't post your code, but the following should work fine:
require('node-xmpp/lib/node-xmpp-browserify.js');
var client = new XMPP.Client(opts);

Meteor - Check if user is logged in as administrator (Client - Side)

I'm currently developing an app which needs users and administrators. What I do right now is, I create an admin account on the client with username 'admin' and a default password that should be changed over the accounts-ui.
I do this because creating a user like this:
Accounts.createUser({
username : 'admin',
email : 'test#test.com',
password : 'changethispasswordovertheuserinterface',
profile : { type : 'admin' }
});
doesn't work for me on server side. That means I just create the admin in my client.js and just use this code to check if the admin is logged in.
Template.admin.isAdmin = function () {
var currentUser = Meteor.user();
// Is this hackable?
if (null !== currentUser) {
if ('admin' === currentUser.username) {
return true;
}
}
};
Is this the best way to approach this? And most importantly, is my site hackable like this (Could somebody fake it)?
Yes this is hackable, one could pull up the chrome inspector and modify this quite easily. Or even faster, by typing something like Template.admin.isAdmin = function () { return true; } into Chrome's web console
The best approach would be to only provide the information to the client from the servers end if the user is an admin. So this would mean using Meteor.allow to ensure the database can only be changed by an administrative user, if peforming ops from the client end.
It also depends a bit on what you want to use 'isAdmin' for too. If its content, you could generate the html on the server's end and send it down to the client in a Meteor.methods. At the moment the templating system doesn't provide for locking down the UI on the clients end depending on what the user's document contains.
For any administrative commands, you could use a Meteor.call at which point the user is vetted on the server's and and the transaction is performed there.
The answer on this thread works too AND the top-voted answer has code for a server side, Meteor method call.

Resources