cnpm / cnpmcore

Private NPM Registry for Enterprise
https://npmmirror.com
MIT License
620 stars 84 forks source link

适配 npm v9 的命令数据更新 #348

Open fengmk2 opened 2 years ago

fengmk2 commented 2 years ago

https://github.blog/changelog/2022-10-24-npm-v9-0-0-released/

login and adduser are now separate commands that send different data to the registry.

login with web

request:

POST /-/v1/login
body: {
  hostname: string,
  create: true | false,
}

response:

{
  doneUrl, loginUrl
}

check doneUrl

GET doneUrl

status: 200
{ token }

status: 202
`retry-after` header in second
fengmk2 commented 2 years ago

https://github.com/npm/cli/pull/5550

fengmk2 commented 2 years ago

实现 login with web

fengmk2 commented 2 years ago

npm login

npm login --registry=https://registry.npmmirror.com --verbose                                                                                         ∞
npm verb cli /.nvs/node/18.12.0/arm64/bin/node /.npm-global/bin/npm
npm info using npm@9.0.1
npm info using node@v18.12.0
npm verb title npm login
npm verb argv "login" "--registry" "https://registry.npmmirror.com" "--loglevel" "verbose"
npm verb logfile logs-max:10 dir:/.npm/_logs/2022-10-28T01_32_03_071Z-
npm verb logfile /.npm/_logs/2022-10-28T01_32_03_071Z-debug-0.log
npm notice Log in on https://registry.npmmirror.com/
npm verb web login before first POST
npm http fetch POST 404 https://registry.npmmirror.com/-/v1/login 169ms
npm verb stack WebLoginNotSupported: Web login not supported
npm verb stack     at /.npm-global/lib/node_modules/npm/node_modules/npm-profile/lib/index.js:96:13
npm verb stack     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
npm verb stack     at async Object.login (//.npm-global/lib/node_modules/npm/lib/utils/auth.js:47:11)
npm verb stack     at async Login.exec (/.npm-global/lib/node_modules/npm/lib/commands/login.js:35:35)
npm verb stack     at async module.exports (/.npm-global/lib/node_modules/npm/lib/cli.js:133:5)
npm verb statusCode 404
npm verb cwd /git/github.com/cnpm/cnpm
npm verb Darwin 21.6.0
npm verb node v18.12.0
npm verb npm  v9.0.1
npm ERR! code ENYI
npm ERR! Web login not supported
npm verb exit 1
npm verb code 1
fengmk2 commented 2 years ago

webAuth 实现 https://github.com/npm/npm-profile/blob/main/lib/index.js#L55 ,老版本也支持 https://github.com/npm/npm-profile/blob/v4/lib/index.js#L41 opener https://github.com/domenic/opener/blob/master/lib/opener.js

fengmk2 commented 2 years ago

这样看来好像得先有一个 web 登录界面😭

MondoGao commented 1 year ago

哈哈,外网应该不需要,内网直接跳登陆服务回来直接转发就好(

fengmk2 commented 1 year ago

@MondoGao 哈哈,不是所有私有部署都会包装一下 npm 的,很多还是直接使用 npm 修改 registry 来使用。

fengmk2 commented 1 year ago

使用 authing.cn 的能力,结合 tegg 的 module 能力,做一个 authing module。

fengmk2 commented 1 year ago
npm http fetch POST 200 https://registry.npmjs.org/-/v1/login 893ms
npm verb web auth got response {
npm verb web auth   loginUrl: 'https://www.npmjs.com/login?next=/login/cli/xxxxx,
npm verb web auth   doneUrl: 'https://registry.npmjs.org/-/v1/done?sessionId=xxx'
npm verb web auth }
npm verb web auth opening url pair
Login at:
https://www.npmjs.com/login?next=/login/cli/xxxxxxx
Press ENTER to open in the browser...npm http fetch GET 202 https://registry.npmjs.org/-/v1/done?sessionId=npm_*** 268ms
npm http fetch GET 202 https://registry.npmjs.org/-/v1/done?sessionId=npm_*** 268ms
npm http fetch GET 202 https://registry.npmjs.org/-/v1/done?sessionId=npm_*** 266ms

登录成功的界面提示 image

fengmk2 commented 1 year ago

baseauth 搞定 image

接下来需要做一个 authing.cn 的 示例