@@ -197,7 +197,7 @@ class PackageManager {
197
197
return this . _registries [ cacheKey ]
198
198
}
199
199
200
- async getAuthToken ( scope ) {
200
+ async getAuthConfig ( scope ) {
201
201
// get npmrc (https://docs.npmjs.com/configuring-npm/npmrc.html#files)
202
202
const possibleRcPaths = [
203
203
path . resolve ( this . context , '.npmrc' ) ,
@@ -225,8 +225,17 @@ class PackageManager {
225
225
. replace ( / h t t p s ? : / , '' ) // remove leading protocol
226
226
. replace ( / ( [ ^ / ] ) $ / , '$1/' ) // ensure ending with slash
227
227
const authTokenKey = `${ registryWithoutProtocol } :_authToken`
228
+ const authUsernameKey = `${ registryWithoutProtocol } :username`
229
+ const authPasswordKey = `${ registryWithoutProtocol } :_password`
228
230
229
- return npmConfig [ authTokenKey ]
231
+ const auth = { }
232
+ if ( authTokenKey in npmConfig ) {
233
+ auth . token = npmConfig [ authTokenKey ]
234
+ }
235
+ if ( authPasswordKey in npmConfig ) {
236
+ auth . username = npmConfig [ authUsernameKey ]
237
+ auth . password = Buffer . from ( npmConfig [ authPasswordKey ] , 'base64' ) . toString ( )
238
+ }
230
239
}
231
240
232
241
async setRegistryEnvs ( ) {
@@ -296,9 +305,13 @@ class PackageManager {
296
305
headers . Accept = 'application/vnd.npm.install-v1+json;q=1.0, application/json;q=0.9, */*;q=0.8'
297
306
}
298
307
299
- const authToken = await this . getAuthToken ( scope )
300
- if ( authToken ) {
301
- headers . Authorization = `Bearer ${ authToken } `
308
+ const authConfig = await this . getAuthToken ( scope )
309
+ if ( 'password' in authConfig ) {
310
+ const credentials = Buffer . from ( `${ authConfig . username } :${ authConfig . password } ` ) . toString ( 'base64' )
311
+ headers . Authorization = `Basic ${ credentials } `
312
+ }
313
+ if ( 'token' in authConfig ) {
314
+ headers . Authorization = `Bearer ${ authConfig . token } `
302
315
}
303
316
304
317
const url = `${ registry . replace ( / \/ $ / g, '' ) } /${ packageName } `
0 commit comments