diff --git a/package.json b/package.json index e1fef1384b..fe69c9e29d 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "promisequence": "1.1.6", "rc": "1.1.6", "read-pkg-up": "1.0.1", - "registry-auth-token": "3.0.1", + "registry-auth-token": "3.1.0", "registry-url": "3.1.0", "retry": "0.10.0", "rimraf-then": "1.0.0", diff --git a/src/network/got.ts b/src/network/got.ts index 3a8e447cf1..af9d88a09d 100644 --- a/src/network/got.ts +++ b/src/network/got.ts @@ -1,12 +1,15 @@ import {IncomingMessage} from 'http' import pauseStream = require('pause-stream') -import getAuthToken = require('registry-auth-token') +import getRegistryAuthInfo = require('registry-auth-token') import createCache from './createCache' import memoize = require('lodash.memoize') export type RequestParams = { - headers?: { - authorization: string + auth?: { + token: string + } | { + username: string, + password: string } } @@ -69,12 +72,24 @@ export default (client: NpmRegistryClient, opts: {cachePath: string, cacheTTL: n } function createOptions (url: string): RequestParams { - const authToken = getAuthToken(url, {recursive: true}) - if (!authToken) return {} - return { - headers: { - authorization: `${authToken.type} ${authToken.token}` - } + const authInfo = getRegistryAuthInfo(url, {recursive: true}) + if (!authInfo) return {} + switch (authInfo.type) { + case 'Bearer': + return { + auth: { + token: authInfo.token + } + } + case 'Basic': + return { + auth: { + username: authInfo.username, + password: authInfo.password + } + } + default: + throw new Error(`Unsupported authorization type '${authInfo.type}'`) } }