afbobak / nopar

Node PAckage Registry
http://afbobak.github.io/nopar/
Other
42 stars 13 forks source link

Nopar behind BasicAuth #23

Open jakef opened 9 years ago

jakef commented 9 years ago

Howdy,

I have nopar running behind nginx with user basic auth. I tried adding auth to my app with, npm config set registry http://user:password@nopar.mywebsite.org. When I run npm install in my app, I receive:

npm ERR! Error: 401 Unauthorized
npm ERR!     at WriteStream.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/fetch.js:58:12)
npm ERR!     at WriteStream.emit (events.js:117:20)
npm ERR!     at evalmachine.<anonymous>:1603:14
npm ERR!     at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:102:5
npm ERR!     at Object.oncomplete (evalmachine.<anonymous>:107:15)

When I look back at my nopar dashboard, some packages were install. In my app however, node_modules fails to generate. Ideas?

afbobak commented 9 years ago

Not sure if this is a bug or an enhancement. At the moment I think it's more an enhancement as the http server probably doesn't understand the username/password part (which shouldn't get to the nopar side of things in the first place).

Can you post your nginx config so I can try to reproduce it?

glenjamin commented 9 years ago

I've managed to get this working recently with an up-to-date version of the npm client.

Rough steps are:

  1. Require HTTP auth on all URLs except those starting with /-/user
  2. npm login --registry <url>
  3. edit ~/.npmrc to set always-auth=true

The general idea is to let the npm client store the credentials separately to the registry URL, and tell it to pass them along on every request. The /-/user stuff is effectively the "login" endpoint for npm, so needs to be accessible without auth.

jakef commented 9 years ago

Oh hello.

auth_basic "Restricted";
auth_basic_user_file mysite_http_basic;

upstream nopar_server {
  server localhost:5984;
}

server {
  listen 80;
  server_name nopar.mysite.org;
  error_log /var/log/nginx/error.log;

  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_pass http://nopar_server;
  }
}