Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm-cli-login does not work #490

Closed
tvb opened this issue Jan 17, 2018 · 9 comments
Closed

npm-cli-login does not work #490

tvb opened this issue Jan 17, 2018 · 9 comments

Comments

@tvb
Copy link

tvb commented Jan 17, 2018

Trying to work around the fact that verdaccio does not support authTokens needed for CI/CD I came accross this npm module https://www.npmjs.com/package/npm-cli-login:

$ npm-cli-login -u username -p password -e emaily@mydomain.com -r http://mydomain.com:5000/ -s @myscope

Results in:

info attempt registry request try #1 at 7:16:39 PM
http request PUT http://mydomain.com:5000/-/user/org.couchdb.user:username
http 409 http://mydomain.com:5000/-/user/org.couchdb.user:username
info attempt registry request try #1 at 7:16:40 PM
http request GET http://mydomain.com:5000/-/user/org.couchdb.user:username?write=true
http 200 http://mydomain.com:5000/-/user/org.couchdb.user:username?write=true
info attempt registry request try #1 at 7:16:40 PM
http request PUT http://mydomain.com:5000/-/user/org.couchdb.user:username/-rev/undefined
http 201 http://mydomain.com:5000/-/user/org.couchdb.user:username/-rev/undefined

And I am not being logged in.

@tvb tvb changed the title npm-login-cli does not work npm-cli-login does not work Jan 17, 2018
@juanpicado
Copy link
Member

juanpicado commented Jan 17, 2018

It works for me

➜ npm-cli-login -u jpicado -p jpicado -e xxxxx@gmail.com -r http://0.0.0.0:4873           
info attempt registry request try #1 at 19:47:03
http request PUT http://0.0.0.0:4873/-/user/org.couchdb.user:jpicado
http 409 http://0.0.0.0:4873/-/user/org.couchdb.user:jpicado
info attempt registry request try #1 at 19:47:03
http request GET http://0.0.0.0:4873/-/user/org.couchdb.user:jpicado?write=true
http 200 http://0.0.0.0:4873/-/user/org.couchdb.user:jpicado?write=true
info attempt registry request try #1 at 19:47:03
http request PUT http://0.0.0.0:4873/-/user/org.couchdb.user:jpicado/-rev/undefined
http 201 http://0.0.0.0:4873/-/user/org.couchdb.user:jpicado/-rev/undefined
(node:70888) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated.

Again with the same Docker image https://github.com/verdaccio/docker-examples/tree/master/docker-local-storage-volume

Docker conf:

version: '2'

services:
  verdaccio:
    image: verdaccio/verdaccio:3.0.0-alpha.9
    container_name: verdaccio-alpha-9
    ports:
      - "4873:4873"
    volumes:
        - "./storage:/verdaccio/storage"
        - "./conf:/verdaccio/conf"

Verdaccio conf:

#
# This is the config file used for the docker images.
# It allows all users to do anything, so don't use it on production systems.
#
# Do not configure host and port under `listen` in this file
# as it will be ignored when using docker.
# see https://github.com/verdaccio/verdaccio/blob/master/wiki/docker.md#docker-and-custom-port-configuration
#
# Look here for more config file examples:
# https://github.com/verdaccio/verdaccio/tree/master/conf
#

# path to a directory with all packages
storage: /verdaccio/storage

auth:
  htpasswd:
    file: /verdaccio/conf/htpasswd
    # Maximum amount of users allowed to register, defaults to "+inf".
    # You can set this to -1 to disable registration.
    #max_users: 1000

# a list of other known repositories we can talk to
uplinks:
  npmjs:
    url: https://registry.npmjs.org/

packages:
  '@jota/*':
      access: $all
      publish: $all

  '@*/*':
    # scoped packages
    access: $all
    publish: $all
    proxy: npmjs

  '**':
    # allow all users (including non-authenticated users) to read and
    # publish all packages
    #
    # you can specify usernames/groupnames (depending on your auth plugin)
    # and three keywords: "$all", "$anonymous", "$authenticated"
    access: $all

    # allow all known users to publish packages
    # (anyone can register by default, remember?)
    publish: $all

    # if package is not available locally, proxy requests to 'npmjs' registry
    proxy: npmjs

# log settings
logs:
  - {type: stdout, format: pretty, level: http}
  #- {type: file, path: verdaccio.log, level: info}

The result in my .npmrc

//0.0.0.0:4873/:_authToken=VfJJdGkZz3ntJPv6GSNHSw==

The first try is without login, second try being logged.

~/WebstormProjects/npm_test_pkg1 is 📦 v1.0.1 via ⬢ v8.7.0 on 🐳 v17.06.2-ce 
➜ npm publish --registry http://0.0.0.0:4873 --tag beta2     
npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/user/.npm/_logs/2018-01-17T18_48_54_122Z-debug.log

~/WebstormProjects/npm_test_pkg1 is 📦 v1.0.1 via ⬢ v8.7.0 on 🐳 v17.06.2-ce 
➜ npm publish --registry http://0.0.0.0:4873 --tag beta2
npm WARN using --force I sure hope you know what you are doing.
npm WARN publish Forced publish over @jota/pk1-juan@1.0.1
+ @jota/pk1-juan@1.0.1

@tvb
Copy link
Author

tvb commented Jan 17, 2018

Checking now. As a side-track I found a wat to get the token directly from verdaccio:

curl -s   -H "Accept: application/json"   -H "Content-Type:application/json"   -X PUT --data '{"name": "myusername", "password": "mypassword", "type": "user"}'   --user myusername:mypassword http://mydomain.com:5000/-/user/org.couchdb.user:myusername 2>&1

gives:

{
  "ok": "you are authenticated as 'myusername'",
  "token": "qRearq2dUsJQsRgxOABeYc83CveitD7YXy+lwddwlwRXzffRdCJZxxqFhqAQl57rLCySDnkevV8CoTC6BeC4DgZQ27TES+dPMqafYkyqFBZ2o70pXg330WEWpT1CCpfTVnLFKBF"
}

I will check npm-cli-login now

@juanpicado
Copy link
Member

Yeah, I haven't dig into what npm-cli-login does internally but I suspect kida the same, my reference is always npm, I know there is an open issue with CI tools but :) if it works locally I'm good.

@tvb
Copy link
Author

tvb commented Jan 17, 2018

Found it!

$ npm-cli-login -u username -p password -e emaily@mydomain.com -r http://mydomain.com:5000/ -s @myscope
$ npm publish --registry=http://mydomain.com:5000/
npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`

Notice the difference missing /

$ npm-cli-login -u username -p password -e emaily@mydomain.com -r http://mydomain.com:5000 -s @myscope
$ npm publish --registry=http://mydomain.com:5000/
+ @myscope/mypackage@0.0.12

@juanpicado
Copy link
Member

🤓 where? I do not see it.

@tvb
Copy link
Author

tvb commented Jan 17, 2018

Ha, copy and paste fail. Edited.

@juanpicado
Copy link
Member

aha! 🎉 ... perfect !! Feel free to close this one :)

@cdtinney
Copy link
Contributor

cdtinney commented Oct 17, 2018

I'm having the same error but was unable to resolve w/ same solution.

I am also unable to authenticate via curl -- I'm not receiving a token in the response:

{
    "ok": "you are authenticated as 'foo'"
}

@lock
Copy link

lock bot commented May 5, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the outdated label May 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants