File tree 2 files changed +15
-16
lines changed
2 files changed +15
-16
lines changed Original file line number Diff line number Diff line change @@ -16,27 +16,25 @@ async function fetch(input: string | URL, init?: RequestInit) {
16
16
input = new URL ( input ) ;
17
17
18
18
let headers = init ?. headers ;
19
- const { username, password} = input ;
19
+
20
+ const username : string | undefined = input . username ?? process . env . COREPACK_NPM_USERNAME ;
21
+ const password : string | undefined = input . password ?? process . env . COREPACK_NPM_PASSWORD ;
22
+
20
23
if ( username || password ) {
21
24
headers = {
22
25
...headers ,
23
- authorization : `Bearer ${ Buffer . from ( `${ username } :${ password } ` ) . toString ( `base64` ) } ` ,
26
+ authorization : `Basic ${ Buffer . from ( `${ username } :${ password } ` ) . toString ( `base64` ) } ` ,
24
27
} ;
28
+
25
29
input . username = input . password = `` ;
26
- } else if ( input . origin === process . env . COREPACK_NPM_REGISTRY || DEFAULT_NPM_REGISTRY_URL ) {
27
- if ( process . env . COREPACK_NPM_TOKEN ) {
28
- headers = {
29
- ...headers ,
30
- authorization : `Bearer ${ process . env . COREPACK_NPM_TOKEN } ` ,
31
- } ;
32
- } else if ( `COREPACK_NPM_PASSWORD` in process . env ) {
33
- headers = {
34
- ...headers ,
35
- authorization : `Bearer ${ Buffer . from ( `${ process . env . COREPACK_NPM_USER } :${ process . env . COREPACK_NPM_PASSWORD } ` ) . toString ( `base64` ) } ` ,
36
- } ;
37
- }
38
30
}
39
31
32
+ if ( input . origin === ( process . env . COREPACK_NPM_REGISTRY || DEFAULT_NPM_REGISTRY_URL ) && process . env . COREPACK_NPM_TOKEN ) {
33
+ headers = {
34
+ ...headers ,
35
+ authorization : `Bearer ${ process . env . COREPACK_NPM_TOKEN } ` ,
36
+ } ;
37
+ }
40
38
41
39
let response ;
42
40
try {
Original file line number Diff line number Diff line change @@ -67,7 +67,8 @@ function generateVersionMetadata(packageName, version) {
67
67
68
68
const server = createServer ( ( req , res ) => {
69
69
const auth = req . headers . authorization ;
70
- if ( ! auth ?. startsWith ( `Bearer ` ) || Buffer . from ( auth . slice ( `Bearer ` . length ) , `base64` ) . toString ( ) !== `user:pass` ) {
70
+
71
+ if ( auth ?. startsWith ( `Basic ` ) && Buffer . from ( auth . slice ( `Basic ` . length ) , `base64` ) . toString ( ) !== `user:pass` ) {
71
72
res . writeHead ( 401 ) . end ( `Unauthorized` ) ;
72
73
return ;
73
74
}
@@ -163,7 +164,7 @@ switch (process.env.AUTH_TYPE) {
163
164
164
165
case `COREPACK_NPM_PASSWORD` :
165
166
process . env . COREPACK_NPM_REGISTRY = `http://${ address . includes ( `:` ) ? `[${ address } ]` : address } :${ port } ` ;
166
- process . env . COREPACK_NPM_USER = `user` ;
167
+ process . env . COREPACK_NPM_USERNAME = `user` ;
167
168
process . env . COREPACK_NPM_PASSWORD = `pass` ;
168
169
break ;
169
170
You can’t perform that action at this time.
0 commit comments