[GH-ISSUE #60] basic auth not working #44

Closed
opened 2026-02-26 05:31:08 +03:00 by kerem · 11 comments
Owner

Originally created by @jochenonline on GitHub (Mar 31, 2013).
Original GitHub issue: https://github.com/NarrativeScience-old/log.io/issues/60

Hi,

this is my web_server.conf:

exports.config = {
  host: '0.0.0.0',
  port: 28778,


  // Enable HTTP Basic Authentication
  auth: {
    user: "test",
    pass: "password"
  },


  /*
  // Enable HTTPS/SSL
  ssl: {
    key: '/path/to/privatekey.pem',
    cert: '/path/to/certificate.pem'
  },
  */

  /*
  // Restrict access to websocket (socket.io)
  // Uses socket.io 'origins' syntax
  restrictSocket: '*:*',
  */

  /*
  // Restrict access to http server (express)
  restrictHTTP: [
    "192.168.29.39",
    "10.0.*"
  ]
  */

}

But when I access the log.io webserver, no username or password is required. The server shows up like without auth. Of course I have restarted the server after changing the conf file. What is wrong?

Originally created by @jochenonline on GitHub (Mar 31, 2013). Original GitHub issue: https://github.com/NarrativeScience-old/log.io/issues/60 Hi, this is my web_server.conf: ``` exports.config = { host: '0.0.0.0', port: 28778, // Enable HTTP Basic Authentication auth: { user: "test", pass: "password" }, /* // Enable HTTPS/SSL ssl: { key: '/path/to/privatekey.pem', cert: '/path/to/certificate.pem' }, */ /* // Restrict access to websocket (socket.io) // Uses socket.io 'origins' syntax restrictSocket: '*:*', */ /* // Restrict access to http server (express) restrictHTTP: [ "192.168.29.39", "10.0.*" ] */ } ``` But when I access the log.io webserver, no username or password is required. The server shows up like without `auth`. Of course I have restarted the server after changing the conf file. What is wrong?
kerem closed this issue 2026-02-26 05:31:09 +03:00
Author
Owner

@d4fseeker commented on GitHub (Apr 4, 2013):

Same problem here on fresh install.
Fixed it by editing the lib/servers.js (/usr/local/lib/node_modules/log.io/lib/servers.js) and adding the following line after line 360:

app.use(express.basicAuth(config.auth.user,config.auth.pass));

It now reads with the line before and after:

staticPath = (_ref = config.staticPath) != null ? _ref : __dirname + '/../';
app.use(express.basicAuth(config.auth.user,config.auth.pass));
return app.use(express"static")

You probably want to add an if/else conditioning to whether the auth already exists.

<!-- gh-comment-id:15899252 --> @d4fseeker commented on GitHub (Apr 4, 2013): Same problem here on fresh install. Fixed it by editing the lib/servers.js (/usr/local/lib/node_modules/log.io/lib/servers.js) and adding the following line after line 360: > app.use(express.basicAuth(config.auth.user,config.auth.pass)); It now reads with the line before and after: > staticPath = (_ref = config.staticPath) != null ? _ref : __dirname + '/../'; > app.use(express.basicAuth(config.auth.user,config.auth.pass)); > return app.use(express["static"](staticPath)) You probably want to add an if/else conditioning to whether the auth already exists.
Author
Owner

@peterfroehlich commented on GitHub (Apr 5, 2013):

Same here.

<!-- gh-comment-id:15954598 --> @peterfroehlich commented on GitHub (Apr 5, 2013): Same here.
Author
Owner

@ecaron commented on GitHub (Apr 22, 2013):

@d4fseeker, should the change in /usr/local/lib/node_modules/log.io/lib/server.js be wrapped in a:

if (config.auth) {
app.use(express.basicAuth(config.auth.user,config.auth.pass));
}

<!-- gh-comment-id:16808633 --> @ecaron commented on GitHub (Apr 22, 2013): @d4fseeker, should the change in /usr/local/lib/node_modules/log.io/lib/server.js be wrapped in a: > if (config.auth) { > app.use(express.basicAuth(config.auth.user,config.auth.pass)); > }
Author
Owner

@d4fseeker commented on GitHub (Apr 22, 2013):

I cannot access a log.io install atm, so you'll have to check but if I remember correctly the wrapper class always exists and thus would return bool/true no matter what.
You'd have to check config.auth.user and config.auth.pass to bypass that, e.g:

if(config.auth.user != null && config.auth.pass != null)
app.use(express.basicAuth(config.auth.user,config.auth.pass));

I have to admit I'm not sure if comparing against null is sufficient since CoffeeScript has made me lazy with it's "?" operator.

<!-- gh-comment-id:16824590 --> @d4fseeker commented on GitHub (Apr 22, 2013): I cannot access a log.io install atm, so you'll have to check but if I remember correctly the wrapper class always exists and thus would return bool/true no matter what. You'd have to check config.auth.user and config.auth.pass to bypass that, e.g: if(config.auth.user != null && config.auth.pass != null) app.use(express.basicAuth(config.auth.user,config.auth.pass)); I have to admit I'm not sure if comparing against null is sufficient since CoffeeScript has made me lazy with it's "?" operator.
Author
Owner

@gu3st commented on GitHub (Apr 23, 2013):

To be perfectly equivalent with Coffeescript's "?" Operator, you'd need to check for both null and undefined.

<!-- gh-comment-id:16836016 --> @gu3st commented on GitHub (Apr 23, 2013): To be perfectly equivalent with Coffeescript's "?" Operator, you'd need to check for both null and undefined.
Author
Owner

@jochenonline commented on GitHub (Jun 5, 2013):

This is the correct syntax:

if (config.auth && config.auth.user && config.auth.pass) {
    app.use(express.basicAuth(config.auth.user,config.auth.pass));
}
<!-- gh-comment-id:18981369 --> @jochenonline commented on GitHub (Jun 5, 2013): This is the correct syntax: ``` if (config.auth && config.auth.user && config.auth.pass) { app.use(express.basicAuth(config.auth.user,config.auth.pass)); } ```
Author
Owner

@blackrosezy commented on GitHub (Aug 26, 2013):

and here is the coffee script :

staticPath = config.staticPath ? __dirname + '/../'
app.use express.basicAuth(config.auth.user, config.auth.pass)  if config.auth and config.auth.user and config.auth.pass
app.use express.static staticPath
<!-- gh-comment-id:23254862 --> @blackrosezy commented on GitHub (Aug 26, 2013): and here is the coffee script : ``` staticPath = config.staticPath ? __dirname + '/../' app.use express.basicAuth(config.auth.user, config.auth.pass) if config.auth and config.auth.user and config.auth.pass app.use express.static staticPath ```
Author
Owner

@Dual-Boot commented on GitHub (Nov 2, 2013):

HI,

For me I fixed it like this (near line 360) file /usr/local/lib/node_modules/log.io/lib/server.js :
staticPath = (_ref = config.staticPath) != null ? _ref : __dirname + '/../';
// add fix start
app.use(express.basicAuth(config.auth.user, config.auth.pass))
if (config.auth && config.auth.user && config.auth.pass)
// fix end
return app.use(express"static");

And It works.

Regards,

<!-- gh-comment-id:27631682 --> @Dual-Boot commented on GitHub (Nov 2, 2013): HI, For me I fixed it like this (near line 360) file /usr/local/lib/node_modules/log.io/lib/server.js : staticPath = (_ref = config.staticPath) != null ? _ref : __dirname + '/../'; // add fix start app.use(express.basicAuth(config.auth.user, config.auth.pass)) if (config.auth && config.auth.user && config.auth.pass) // fix end return app.use(express["static"](staticPath)); And It works. Regards,
Author
Owner

@albertojm commented on GitHub (Dec 10, 2013):

Hi, I've downloaded & installed log.io today and still have no auth, my config file looks like:

exports.config = {
host: '0.0.0.0',
port: 28778,

// Enable HTTP Basic Authentication
auth: {
user: "test",
pass: "test123"
},

/*
// Enable HTTPS/SSL
ssl: {
key: '/path/to/privatekey.pem',
cert: '/path/to/certificate.pem'
},
*/

/*
// Restrict access to websocket (socket.io)
// Uses socket.io 'origins' syntax
restrictSocket: ':',
*/

/*
// Restrict access to http server (express)
restrictHTTP: [
"192.168.29.39",
"10.0.*"
]
*/
}

Any hint on why this is happening?

Thanks for your help.

<!-- gh-comment-id:30257448 --> @albertojm commented on GitHub (Dec 10, 2013): Hi, I've downloaded & installed log.io today and still have no auth, my config file looks like: exports.config = { host: '0.0.0.0', port: 28778, // Enable HTTP Basic Authentication auth: { user: "test", pass: "test123" }, /* // Enable HTTPS/SSL ssl: { key: '/path/to/privatekey.pem', cert: '/path/to/certificate.pem' }, */ /* // Restrict access to websocket (socket.io) // Uses socket.io 'origins' syntax restrictSocket: '_:_', */ /* // Restrict access to http server (express) restrictHTTP: [ "192.168.29.39", "10.0.*" ] */ } Any hint on why this is happening? Thanks for your help.
Author
Owner

@vansteki commented on GitHub (Dec 18, 2013):

@albertojm, i install by npm today and i have same problom.

if you check /usr/lib/node_modules/log.io/src/server.coffee, you'll find something missing around line 180 and 181:
if @auth?
app.use express.basicAuth @auth.user, @auth.pass

it looks like code in npm is not the same in current repo...?

try add these to /usr/lib/node_modules/log.io/lib/server.js

app = express();
...
   //just add these three line below
   if (this.auth != null) {
          app.use(express.basicAuth(this.auth.user, this.auth.pass));
   }
...
if (config.restrictHTTP) {

then edit config file and run

it works for me!

<!-- gh-comment-id:30837346 --> @vansteki commented on GitHub (Dec 18, 2013): @albertojm, i install by npm today and i have same problom. if you check `/usr/lib/node_modules/log.io/src/server.coffee`, you'll find something missing around line 180 and 181: `if @auth?` `app.use express.basicAuth @auth.user, @auth.pass` it looks like code in npm is not the same in current repo...? try add these to `/usr/lib/node_modules/log.io/lib/server.js` ``` app = express(); ... //just add these three line below if (this.auth != null) { app.use(express.basicAuth(this.auth.user, this.auth.pass)); } ... if (config.restrictHTTP) { ``` then edit config file and run it works for me!
Author
Owner

@crackfoo commented on GitHub (Jun 4, 2014):

Thanks @vansteki ! that worked for me too.

<!-- gh-comment-id:45085521 --> @crackfoo commented on GitHub (Jun 4, 2014): Thanks @vansteki ! that worked for me too.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/log.io-NarrativeScience-old#44
No description provided.