@@ -73,13 +73,19 @@ function hasCredentials(obj: any): boolean {
7373}
7474
7575function hasBasicCredentials ( obj : any ) : boolean {
76- return obj && obj . username && obj . password && obj . username !== 'apikey' ;
76+ return obj && obj . username && obj . password && ! usesBasicForIam ( obj ) ;
7777}
7878
7979function hasIamCredentials ( obj : any ) : boolean {
8080 return obj && ( obj . iam_apikey || obj . iam_access_token ) ;
8181}
8282
83+ // returns true if the user provides basic auth creds with the intention
84+ // of using IAM auth
85+ function usesBasicForIam ( obj : any ) : boolean {
86+ return obj . username === 'apikey' && ! obj . password . startsWith ( 'icp-' ) ;
87+ }
88+
8389export class BaseService {
8490 static URL : string ;
8591 name : string ;
@@ -135,7 +141,7 @@ export class BaseService {
135141 iamAccessToken : _options . iam_access_token ,
136142 iamUrl : _options . iam_url
137143 } ) ;
138- } else if ( _options . username === 'apikey' ) {
144+ } else if ( usesBasicForIam ( _options ) ) {
139145 this . tokenManager = new IamTokenManagerV1 ( {
140146 iamApikey : _options . password ,
141147 iamUrl : _options . iam_url
@@ -280,7 +286,7 @@ export class BaseService {
280286 'api_key, and iam_access_token.' ;
281287 throw new Error ( errorMessage ) ;
282288 }
283- if ( ! hasIamCredentials ( _options ) && _options . username !== 'apikey' ) {
289+ if ( ! hasIamCredentials ( _options ) && ! usesBasicForIam ( _options ) ) {
284290 if ( hasBasicCredentials ( _options ) ) {
285291 // Calculate and add Authorization header to base options
286292 const encodedCredentials = bufferFrom (
0 commit comments