Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

npm login过后,authorization如何取值 #1578

Closed
kaiyilian opened this issue Jun 28, 2020 · 0 comments
Closed

npm login过后,authorization如何取值 #1578

kaiyilian opened this issue Jun 28, 2020 · 0 comments

Comments

@kaiyilian
Copy link

我们搭建了一个私有仓库,在npm install的时候,会统计自定义的package下载数量和时间。
这个接口是在origin_npm.js里面自定义的

child.on('exit', code => {
	// 发送下载包情况
		request({
			url: theRegistry + '/package/install/statistics',
			method: 'POST',
			json: true,
			headers: {
				"content-type": 'application/json',
				'authorization':'Bearer SB3bt4d====A98zFniankw=='  //authorization要如何取值???
			},
			body: JSON.stringify(postParam)
		}, () => {
			process.exit(code);
		});
	} else {
		process.exit(code);
	}
});

但是统计的时候获取不到当前登录用户的信息,后来发现npm login过后,每次请求,都会在header中把authorization解析成remote_user,

req.headers===middlewar.js { connection: 'keep-alive',
  'user-agent': 'npm/6.14.5 node/v8.16.1 win32 x64',
  'npm-in-ci': 'false',
  'npm-scope': '',
  'npm-session': 'a9d3de1522c7d73f',
  referer: 'install vue',
  authorization: 'Bearer SB3bt4dn3vkA98zFniankw==',      // 这个就是接口请求会传过来的authorization
  'content-type': 'application/json',
  'content-encoding': 'gzip',
  accept: '*/*',
  'content-length': '215',
  'accept-encoding': 'gzip,deflate',
  host: 'localhost:4873' }

但是authorization这个字段不知道怎么取值,传给接口

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants