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 v9 的命令数据更新 #348

Open
fengmk2 opened this issue Oct 28, 2022 · 12 comments
Open

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

fengmk2 opened this issue Oct 28, 2022 · 12 comments
Assignees
Labels
enhancement New feature or request

Comments

@fengmk2
Copy link
Member

fengmk2 commented Oct 28, 2022

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
Copy link
Member Author

fengmk2 commented Oct 28, 2022

npm/cli#5550

@fengmk2
Copy link
Member Author

fengmk2 commented Oct 28, 2022

实现 login with web

@fengmk2
Copy link
Member Author

fengmk2 commented Oct 28, 2022

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 fengmk2 added the enhancement New feature or request label Oct 28, 2022
@fengmk2 fengmk2 self-assigned this Oct 28, 2022
@fengmk2
Copy link
Member Author

fengmk2 commented Oct 28, 2022

@fengmk2
Copy link
Member Author

fengmk2 commented Oct 28, 2022

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

@MondoGao
Copy link

MondoGao commented Dec 1, 2022

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

@fengmk2
Copy link
Member Author

fengmk2 commented Jan 18, 2023

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

This was referenced Jan 18, 2023
@fengmk2
Copy link
Member Author

fengmk2 commented Jan 18, 2023

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

@fengmk2
Copy link
Member Author

fengmk2 commented Jan 22, 2023

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
Copy link
Member Author

fengmk2 commented Feb 21, 2023

baseauth 搞定
image

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

@dennisleung
Copy link

npm v9+版本的login请求体已经没有hostname参数了,见npm-profile源码。WebAuthController中的LoginRequestRule是不是应该调整成这样比较好?

const LoginRequestRule = Type.Object({
  // cli 所在机器的 hostname,NPM9+开始去掉
  hostname: Type.Optional(Type.String({ minLength: 1, maxLength: 100 })),
});

@fengmk2
Copy link
Member Author

fengmk2 commented Dec 9, 2024

npm v9+版本的login请求体已经没有hostname参数了,见npm-profile源码。WebAuthController中的LoginRequestRule是不是应该调整成这样比较好?

const LoginRequestRule = Type.Object({
  // cli 所在机器的 hostname,NPM9+开始去掉
  hostname: Type.Optional(Type.String({ minLength: 1, maxLength: 100 })),
});

可以来一个 pr 修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants