@@ -3,6 +3,7 @@ import {MessageName, ReportError} from '@yarnpkg/core';
33import { prompt } from 'enquirer' ;
44import { URL } from 'url' ;
55
6+ import { Hooks } from "./Hooks" ;
67import * as npmConfigUtils from './npmConfigUtils' ;
78import { MapLike } from './npmConfigUtils' ;
89
@@ -60,7 +61,7 @@ export async function get(path: string, {configuration, headers, ident, authType
6061 if ( typeof registry !== `string` )
6162 throw new Error ( `Assertion failed: The registry should be a string` ) ;
6263
63- const auth = getAuthenticationHeader ( registry , { authType, configuration, ident} ) ;
64+ const auth = await getAuthenticationHeader ( registry , { authType, configuration, ident} ) ;
6465 if ( auth )
6566 headers = { ...headers , authorization : auth } ;
6667
@@ -87,7 +88,7 @@ export async function post(path: string, body: httpUtils.Body, {attemptedAs, con
8788 if ( typeof registry !== `string` )
8889 throw new Error ( `Assertion failed: The registry should be a string` ) ;
8990
90- const auth = getAuthenticationHeader ( registry , { authType, configuration, ident} ) ;
91+ const auth = await getAuthenticationHeader ( registry , { authType, configuration, ident} ) ;
9192 if ( auth )
9293 headers = { ...headers , authorization : auth } ;
9394
@@ -121,7 +122,7 @@ export async function put(path: string, body: httpUtils.Body, {attemptedAs, conf
121122 if ( typeof registry !== `string` )
122123 throw new Error ( `Assertion failed: The registry should be a string` ) ;
123124
124- const auth = getAuthenticationHeader ( registry , { authType, configuration, ident} ) ;
125+ const auth = await getAuthenticationHeader ( registry , { authType, configuration, ident} ) ;
125126 if ( auth )
126127 headers = { ...headers , authorization : auth } ;
127128
@@ -155,7 +156,7 @@ export async function del(path: string, {attemptedAs, configuration, headers, id
155156 if ( typeof registry !== `string` )
156157 throw new Error ( `Assertion failed: The registry should be a string` ) ;
157158
158- const auth = getAuthenticationHeader ( registry , { authType, configuration, ident} ) ;
159+ const auth = await getAuthenticationHeader ( registry , { authType, configuration, ident} ) ;
159160 if ( auth )
160161 headers = { ...headers , authorization : auth } ;
161162
@@ -182,13 +183,21 @@ export async function del(path: string, {attemptedAs, configuration, headers, id
182183 }
183184}
184185
185- function getAuthenticationHeader ( registry : string , { authType = AuthType . CONFIGURATION , configuration, ident} : { authType ?: AuthType , configuration : Configuration , ident : RegistryOptions [ 'ident' ] } ) {
186+ async function getAuthenticationHeader ( registry : string , { authType = AuthType . CONFIGURATION , configuration, ident} : { authType ?: AuthType , configuration : Configuration , ident : RegistryOptions [ 'ident' ] } ) {
186187 const effectiveConfiguration = npmConfigUtils . getAuthConfiguration ( registry , { configuration, ident} ) ;
187188 const mustAuthenticate = shouldAuthenticate ( effectiveConfiguration , authType ) ;
188189
189190 if ( ! mustAuthenticate )
190191 return null ;
191192
193+ const header = await configuration . reduceHook ( ( hooks : Hooks ) => {
194+ return hooks . getNpmAuthenticationHeader ;
195+ } , undefined , registry , { configuration, ident} ) ;
196+
197+ if ( header )
198+ return header ;
199+
200+
192201 if ( effectiveConfiguration . get ( `npmAuthToken` ) )
193202 return `Bearer ${ effectiveConfiguration . get ( `npmAuthToken` ) } ` ;
194203 if ( effectiveConfiguration . get ( `npmAuthIdent` ) )
0 commit comments