@@ -73,13 +73,19 @@ function hasCredentials(obj: any): boolean {
73
73
}
74
74
75
75
function hasBasicCredentials ( obj : any ) : boolean {
76
- return obj && obj . username && obj . password && obj . username !== 'apikey' ;
76
+ return obj && obj . username && obj . password && ! usesBasicForIam ( obj ) ;
77
77
}
78
78
79
79
function hasIamCredentials ( obj : any ) : boolean {
80
80
return obj && ( obj . iam_apikey || obj . iam_access_token ) ;
81
81
}
82
82
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
+
83
89
export class BaseService {
84
90
static URL : string ;
85
91
name : string ;
@@ -135,7 +141,7 @@ export class BaseService {
135
141
iamAccessToken : _options . iam_access_token ,
136
142
iamUrl : _options . iam_url
137
143
} ) ;
138
- } else if ( _options . username === 'apikey' ) {
144
+ } else if ( usesBasicForIam ( _options ) ) {
139
145
this . tokenManager = new IamTokenManagerV1 ( {
140
146
iamApikey : _options . password ,
141
147
iamUrl : _options . iam_url
@@ -280,7 +286,7 @@ export class BaseService {
280
286
'api_key, and iam_access_token.' ;
281
287
throw new Error ( errorMessage ) ;
282
288
}
283
- if ( ! hasIamCredentials ( _options ) && _options . username !== 'apikey' ) {
289
+ if ( ! hasIamCredentials ( _options ) && ! usesBasicForIam ( _options ) ) {
284
290
if ( hasBasicCredentials ( _options ) ) {
285
291
// Calculate and add Authorization header to base options
286
292
const encodedCredentials = bufferFrom (
0 commit comments