ibm-cloud-sdk-core 5.3.2 → 5.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/auth/authenticators/authenticator.d.ts +2 -1
  2. package/auth/authenticators/authenticator.js +1 -0
  3. package/auth/authenticators/index.d.ts +3 -1
  4. package/auth/authenticators/index.js +3 -1
  5. package/auth/authenticators/mcsp-authenticator.d.ts +2 -4
  6. package/auth/authenticators/mcsp-authenticator.js +2 -4
  7. package/auth/authenticators/mcspv2-authenticator.d.ts +95 -0
  8. package/auth/authenticators/mcspv2-authenticator.js +85 -0
  9. package/auth/token-managers/index.d.ts +6 -3
  10. package/auth/token-managers/index.js +8 -4
  11. package/auth/token-managers/jwt-token-manager.js +6 -3
  12. package/auth/token-managers/mcspv2-token-manager.d.ts +112 -0
  13. package/auth/token-managers/mcspv2-token-manager.js +176 -0
  14. package/auth/token-managers/token-manager.d.ts +1 -1
  15. package/auth/token-managers/token-manager.js +1 -1
  16. package/auth/utils/get-authenticator-from-environment.d.ts +1 -1
  17. package/auth/utils/get-authenticator-from-environment.js +4 -1
  18. package/docs/ibm-cloud-sdk-core.api.json +293 -5
  19. package/es/auth/authenticators/authenticator.d.ts +2 -1
  20. package/es/auth/authenticators/authenticator.js +1 -0
  21. package/es/auth/authenticators/index.d.ts +3 -1
  22. package/es/auth/authenticators/index.js +1 -0
  23. package/es/auth/authenticators/mcsp-authenticator.d.ts +2 -4
  24. package/es/auth/authenticators/mcsp-authenticator.js +2 -4
  25. package/es/auth/authenticators/mcspv2-authenticator.d.ts +95 -0
  26. package/es/auth/authenticators/mcspv2-authenticator.js +63 -0
  27. package/es/auth/token-managers/index.d.ts +6 -3
  28. package/es/auth/token-managers/index.js +6 -3
  29. package/es/auth/token-managers/jwt-token-manager.js +6 -3
  30. package/es/auth/token-managers/mcspv2-token-manager.d.ts +112 -0
  31. package/es/auth/token-managers/mcspv2-token-manager.js +151 -0
  32. package/es/auth/token-managers/token-manager.d.ts +1 -1
  33. package/es/auth/token-managers/token-manager.js +1 -1
  34. package/es/auth/utils/get-authenticator-from-environment.d.ts +1 -1
  35. package/es/auth/utils/get-authenticator-from-environment.js +5 -2
  36. package/es/lib/request-wrapper.d.ts +1 -1
  37. package/es/lib/request-wrapper.js +8 -3
  38. package/ibm-cloud-sdk-core.d.ts +183 -7
  39. package/lib/request-wrapper.d.ts +1 -1
  40. package/lib/request-wrapper.js +8 -3
  41. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2023.
2
+ * (C) Copyright IBM Corp. 2023, 2025.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -29,8 +29,6 @@ export class McspAuthenticator extends TokenRequestBasedAuthenticator {
29
29
  * @param options - Configuration options for CloudPakForData authentication.
30
30
  * This should be an object containing these fields:
31
31
  * - url: (required) the endpoint URL for the CloudPakForData token service
32
- * - username: (required) the username used to obtain a bearer token
33
- * - password: (optional) the password used to obtain a bearer token (required if apikey is not specified)
34
32
  * - apikey: (optional) the API key used to obtain a bearer token (required if password is not specified)
35
33
  * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate
36
34
  * should be disabled or not
@@ -49,7 +47,7 @@ export class McspAuthenticator extends TokenRequestBasedAuthenticator {
49
47
  this.tokenManager = new McspTokenManager(options);
50
48
  }
51
49
  /**
52
- * Returns the authenticator's type ('cp4d').
50
+ * Returns the authenticator's type ('mcsp').
53
51
  *
54
52
  * @returns a string that indicates the authenticator's type
55
53
  */
@@ -0,0 +1,95 @@
1
+ /**
2
+ * (C) Copyright IBM Corp. 2025.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { BaseOptions, TokenRequestBasedAuthenticator } from './token-request-based-authenticator';
17
+ import { McspV2TokenManager } from '../token-managers/mcspv2-token-manager';
18
+ /** Configuration options for Multi-Cloud Saas Platform (MCSP) v2 authentication. */
19
+ export interface Options extends BaseOptions {
20
+ /**
21
+ * (required) The API key used to obtain an MCSP access token.
22
+ */
23
+ apikey: string;
24
+ /**
25
+ * (required) The URL representing the MCSP token service endpoint.
26
+ */
27
+ url: string;
28
+ /**
29
+ * (required) The scope collection type of item(s).
30
+ * Valid values are: "accounts", "subscriptions", "services".
31
+ */
32
+ scopeCollectionType: string;
33
+ /**
34
+ * (required) The scope identifier of item(s).
35
+ */
36
+ scopeId: string;
37
+ /**
38
+ * (optional) A flag to include builtin actions in the "actions" claim in the MCSP access token (default: false).
39
+ */
40
+ includeBuiltinActions?: boolean;
41
+ /**
42
+ * (optional) A flag to include custom actions in the "actions" claim in the MCSP access token (default: false).
43
+ */
44
+ includeCustomActions?: boolean;
45
+ /**
46
+ * (optional) A flag to include the "roles" claim in the MCSP access token (default: true).
47
+ */
48
+ includeRoles?: boolean;
49
+ /**
50
+ * (optional) A flag to add a prefix with the scope level where the role is defined in the "roles" claim (default: false).
51
+ */
52
+ prefixRoles?: boolean;
53
+ /**
54
+ * (optional) A map (object) containing keys and values to be injected into the access token as the "callerExt" claim.
55
+ * The keys used in this map must be enabled in the apikey by setting the "callerExtClaimNames" property when the apikey is created.
56
+ * This property is typically only used in scenarios involving an apikey with identityType `SERVICEID`.
57
+ */
58
+ callerExtClaim?: object;
59
+ }
60
+ /**
61
+ * The McspV2Authenticator invokes the MCSP v2 token-exchange operation (POST /api/2.0/\{scopeCollectionType\}/\{scopeId\}/apikeys/token)
62
+ * to obtain an access token for an apikey, and adds the access token to requests via an Authorization header
63
+ * of the form: "Authorization: Bearer <access-token>"
64
+ */
65
+ export declare class McspV2Authenticator extends TokenRequestBasedAuthenticator {
66
+ protected tokenManager: McspV2TokenManager;
67
+ /**
68
+ * Create a new McspV2Authenticator instance.
69
+ *
70
+ * @param options - Configuration options for MCSP v2 authentication.
71
+ * This should be an object containing these fields:
72
+ * - url: (required) the endpoint URL for the CloudPakForData token service.
73
+ * - apikey: (optional) the API key used to obtain a bearer token (required if password is not specified).
74
+ * - scopeCollectionType: (required) The scope collection type of item(s). Valid values are: "accounts", "subscriptions", "services".
75
+ * - scopeId: (required) the scope identifier of item(s).
76
+ * - includeBuiltinActions: (optional) a flag to include builtin actions in the "actions" claim in the MCSP access token (default: false).
77
+ * - includeCustomActions: (optional) a flag to include custom actions in the "actions" claim in the MCSP access token (default: false).
78
+ * - includeRoles: (optional) a flag to include the "roles" claim in the MCSP access token (default: true).
79
+ * - prefixRoles: (optional) a flag to add a prefix with the scope level where the role is defined in the "roles" claim (default: false).
80
+ * - callerExtClaim: (optional) a map (object) containing keys and values to be injected into the access token as the "callerExt" claim.
81
+ * The keys used in this map must be enabled in the apikey by setting the "callerExtClaimNames" property when the apikey is created.
82
+ * This property is typically only used in scenarios involving an apikey with identityType `SERVICEID`.
83
+ * - disableSslVerification: (optional) a flag to disable verification of the token server's SSL certificate; defaults to false.
84
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service.
85
+ *
86
+ * @throws Error: the input configuration failed validation
87
+ */
88
+ constructor(options: Options);
89
+ /**
90
+ * Returns the authenticator's type ('mcspv2').
91
+ *
92
+ * @returns a string that indicates the authenticator's type
93
+ */
94
+ authenticationType(): string;
95
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * (C) Copyright IBM Corp. 2025.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Authenticator } from './authenticator';
17
+ import { TokenRequestBasedAuthenticator } from './token-request-based-authenticator';
18
+ import { McspV2TokenManager } from '../token-managers/mcspv2-token-manager';
19
+ /**
20
+ * The McspV2Authenticator invokes the MCSP v2 token-exchange operation (POST /api/2.0/\{scopeCollectionType\}/\{scopeId\}/apikeys/token)
21
+ * to obtain an access token for an apikey, and adds the access token to requests via an Authorization header
22
+ * of the form: "Authorization: Bearer <access-token>"
23
+ */
24
+ export class McspV2Authenticator extends TokenRequestBasedAuthenticator {
25
+ /**
26
+ * Create a new McspV2Authenticator instance.
27
+ *
28
+ * @param options - Configuration options for MCSP v2 authentication.
29
+ * This should be an object containing these fields:
30
+ * - url: (required) the endpoint URL for the CloudPakForData token service.
31
+ * - apikey: (optional) the API key used to obtain a bearer token (required if password is not specified).
32
+ * - scopeCollectionType: (required) The scope collection type of item(s). Valid values are: "accounts", "subscriptions", "services".
33
+ * - scopeId: (required) the scope identifier of item(s).
34
+ * - includeBuiltinActions: (optional) a flag to include builtin actions in the "actions" claim in the MCSP access token (default: false).
35
+ * - includeCustomActions: (optional) a flag to include custom actions in the "actions" claim in the MCSP access token (default: false).
36
+ * - includeRoles: (optional) a flag to include the "roles" claim in the MCSP access token (default: true).
37
+ * - prefixRoles: (optional) a flag to add a prefix with the scope level where the role is defined in the "roles" claim (default: false).
38
+ * - callerExtClaim: (optional) a map (object) containing keys and values to be injected into the access token as the "callerExt" claim.
39
+ * The keys used in this map must be enabled in the apikey by setting the "callerExtClaimNames" property when the apikey is created.
40
+ * This property is typically only used in scenarios involving an apikey with identityType `SERVICEID`.
41
+ * - disableSslVerification: (optional) a flag to disable verification of the token server's SSL certificate; defaults to false.
42
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service.
43
+ *
44
+ * @throws Error: the input configuration failed validation
45
+ */
46
+ constructor(options) {
47
+ super(options);
48
+ // All we really need to do is construct the token manager, passing in
49
+ // our Options object since it contains the same fields as the
50
+ // token manager's Options interface.
51
+ // Note that the token manager handles input validation.
52
+ this.tokenManager = new McspV2TokenManager(options);
53
+ }
54
+ /**
55
+ * Returns the authenticator's type ('mcspv2').
56
+ *
57
+ * @returns a string that indicates the authenticator's type
58
+ */
59
+ // eslint-disable-next-line class-methods-use-this
60
+ authenticationType() {
61
+ return Authenticator.AUTHTYPE_MCSPV2;
62
+ }
63
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2019, 2023.
2
+ * (C) Copyright IBM Corp. 2019, 2025.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -21,7 +21,8 @@
21
21
  * Cloud Pak for Data
22
22
  * Container (IKS, etc)
23
23
  * VPC Instance
24
- * Multi-Cloud Saas Platform (MCSP)
24
+ * Multi-Cloud Saas Platform (MCSP) V1
25
+ * Multi-Cloud Saas Platform (MCSP) V2
25
26
  *
26
27
  * The token managers sit inside of an authenticator and do the work to retrieve
27
28
  * tokens, whereas the authenticators add these tokens to the actual request.
@@ -32,7 +33,8 @@
32
33
  * Cp4dTokenManager: Token Manager of CloudPak for data.
33
34
  * ContainerTokenManager: Token manager of IAM via compute resource token.
34
35
  * VpcInstanceTokenManager: Token manager of VPC Instance Metadata Service API tokens.
35
- * McspTokenManager: Token Manager of MCSP via apikey.
36
+ * McspTokenManager: Token Manager of MCSP v1 via apikey.
37
+ * McspV2TokenManager: Token Manager of MCSP v2 via apikey.
36
38
  * JwtTokenManager: A class for shared functionality for parsing, storing, and requesting JWT tokens.
37
39
  */
38
40
  export { IamTokenManager } from './iam-token-manager';
@@ -43,4 +45,5 @@ export { JwtTokenManager, JwtTokenManagerOptions } from './jwt-token-manager';
43
45
  export { TokenManager, TokenManagerOptions } from './token-manager';
44
46
  export { VpcInstanceTokenManager } from './vpc-instance-token-manager';
45
47
  export { McspTokenManager } from './mcsp-token-manager';
48
+ export { McspV2TokenManager } from './mcspv2-token-manager';
46
49
  export { IamAssumeTokenManager } from './iam-assume-token-manager';
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2019, 2023.
2
+ * (C) Copyright IBM Corp. 2019, 2025.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -21,7 +21,8 @@
21
21
  * Cloud Pak for Data
22
22
  * Container (IKS, etc)
23
23
  * VPC Instance
24
- * Multi-Cloud Saas Platform (MCSP)
24
+ * Multi-Cloud Saas Platform (MCSP) V1
25
+ * Multi-Cloud Saas Platform (MCSP) V2
25
26
  *
26
27
  * The token managers sit inside of an authenticator and do the work to retrieve
27
28
  * tokens, whereas the authenticators add these tokens to the actual request.
@@ -32,7 +33,8 @@
32
33
  * Cp4dTokenManager: Token Manager of CloudPak for data.
33
34
  * ContainerTokenManager: Token manager of IAM via compute resource token.
34
35
  * VpcInstanceTokenManager: Token manager of VPC Instance Metadata Service API tokens.
35
- * McspTokenManager: Token Manager of MCSP via apikey.
36
+ * McspTokenManager: Token Manager of MCSP v1 via apikey.
37
+ * McspV2TokenManager: Token Manager of MCSP v2 via apikey.
36
38
  * JwtTokenManager: A class for shared functionality for parsing, storing, and requesting JWT tokens.
37
39
  */
38
40
  export { IamTokenManager } from './iam-token-manager';
@@ -43,4 +45,5 @@ export { JwtTokenManager } from './jwt-token-manager';
43
45
  export { TokenManager } from './token-manager';
44
46
  export { VpcInstanceTokenManager } from './vpc-instance-token-manager';
45
47
  export { McspTokenManager } from './mcsp-token-manager';
48
+ export { McspV2TokenManager } from './mcspv2-token-manager';
46
49
  export { IamAssumeTokenManager } from './iam-assume-token-manager';
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable class-methods-use-this */
2
2
  /**
3
- * (C) Copyright IBM Corp. 2019, 2024.
3
+ * (C) Copyright IBM Corp. 2019, 2025.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -71,8 +71,9 @@ export class JwtTokenManager extends TokenManager {
71
71
  logger.error(err);
72
72
  throw new Error(err);
73
73
  }
74
- // the time of expiration is found by decoding the JWT access token
75
- // 'exp' is the time of expire and 'iat' is the time of token retrieval
74
+ // The expiration time is found by decoding the JWT access token.
75
+ // 'exp' is the "expiration time" claim.
76
+ // 'iat' is the 'issued at' claim.
76
77
  const { exp, iat } = decodedResponse;
77
78
  // There are no required claims in JWT
78
79
  if (!exp || !iat) {
@@ -83,6 +84,8 @@ export class JwtTokenManager extends TokenManager {
83
84
  const fractionOfTtl = 0.8;
84
85
  const timeToLive = exp - iat;
85
86
  this.expireTime = exp;
87
+ // The refresh time represents the time when the token has effectively
88
+ // existed for 80% of its time to live.
86
89
  this.refreshTime = exp - timeToLive * (1.0 - fractionOfTtl);
87
90
  }
88
91
  this.tokenInfo = Object.assign({}, responseBody);
@@ -0,0 +1,112 @@
1
+ /**
2
+ * (C) Copyright IBM Corp. 2025.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { JwtTokenManager, JwtTokenManagerOptions } from './jwt-token-manager';
17
+ /**
18
+ * Configuration options for MCSP v2 token retrieval.
19
+ */
20
+ interface Options extends JwtTokenManagerOptions {
21
+ /**
22
+ * (required) The API key used to obtain an MCSP access token.
23
+ */
24
+ apikey: string;
25
+ /**
26
+ * (required) The URL representing the MCSP token service endpoint.
27
+ */
28
+ url: string;
29
+ /**
30
+ * (required) The scope collection type of item(s).
31
+ * Valid values are: "accounts", "subscriptions", "services".
32
+ */
33
+ scopeCollectionType: string;
34
+ /**
35
+ * (required) The scope identifier of item(s).
36
+ */
37
+ scopeId: string;
38
+ /**
39
+ * (optional) A flag to include builtin actions in the "actions" claim in the MCSP access token (default: false).
40
+ */
41
+ includeBuiltinActions?: boolean;
42
+ /**
43
+ * (optional) A flag to include custom actions in the "actions" claim in the MCSP access token (default: false).
44
+ */
45
+ includeCustomActions?: boolean;
46
+ /**
47
+ * (optional) A flag to include the "roles" claim in the MCSP access token (default: true).
48
+ */
49
+ includeRoles?: boolean;
50
+ /**
51
+ * (optional) A flag to add a prefix with the scope level where the role is defined in the "roles" claim (default: false).
52
+ */
53
+ prefixRoles?: boolean;
54
+ /**
55
+ * (optional) A map (object) containing keys and values to be injected into the access token as the "callerExt" claim.
56
+ * The keys used in this map must be enabled in the apikey by setting the "callerExtClaimNames" property when the apikey is created.
57
+ * This property is typically only used in scenarios involving an apikey with identityType `SERVICEID`.
58
+ */
59
+ callerExtClaim?: object;
60
+ }
61
+ /**
62
+ * Token Manager for Multi-Cloud Saas Platform (MCSP) V2 authentication.
63
+ *
64
+ * The McspV2TokenManager will invoke the MCSP token service's 'POST /api/2.0/\{scopeCollectionType\}/\{scopeId\}/apikeys/token'
65
+ * operation to obtain an MCSP access token for an apikey.
66
+ */
67
+ export declare class McspV2TokenManager extends JwtTokenManager {
68
+ protected requiredOptions: string[];
69
+ private apikey;
70
+ private scopeCollectionType;
71
+ private scopeId;
72
+ private includeBuiltinActions;
73
+ private includeCustomActions;
74
+ private includeRoles;
75
+ private prefixRoles;
76
+ private callerExtClaim;
77
+ /**
78
+ * Create a new McspV2TokenManager instance.
79
+ *
80
+ * @param options - Configuration options.
81
+ * This should be an object containing these fields:
82
+ * - url: (required) the endpoint URL for the CloudPakForData token service.
83
+ * - apikey: (optional) the API key used to obtain a bearer token (required if password is not specified).
84
+ * - scopeCollectionType: (required) The scope collection type of item(s). Valid values are: "accounts", "subscriptions", "services".
85
+ * - scopeId: (required) the scope identifier of item(s).
86
+ * - includeBuiltinActions: (optional) a flag to include builtin actions in the "actions" claim in the MCSP access token (default: false).
87
+ * - includeCustomActions: (optional) a flag to include custom actions in the "actions" claim in the MCSP access token (default: false).
88
+ * - includeRoles: (optional) a flag to include the "roles" claim in the MCSP access token (default: true).
89
+ * - prefixRoles: (optional) a flag to add a prefix with the scope level where the role is defined in the "roles" claim (default: false).
90
+ * - callerExtClaim: (optional) a map (object) containing keys and values to be injected into the access token as the "callerExt" claim.
91
+ * The keys used in this map must be enabled in the apikey by setting the "callerExtClaimNames" property when the apikey is created.
92
+ * This property is typically only used in scenarios involving an apikey with identityType `SERVICEID`.
93
+ * - disableSslVerification: (optional) a flag to disable verification of the token server's SSL certificate; defaults to false.
94
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service.
95
+ *
96
+ * @throws Error: the input configuration failed validation
97
+ */
98
+ constructor(options: Options);
99
+ private PATH_TEMPLATE;
100
+ protected requestToken(): Promise<any>;
101
+ /**
102
+ * Parses the Options configuration property named by 'fieldName' as a boolean value.
103
+ * The value in the Options object could be either boolean or string and this function
104
+ * will do its best to parse it correctly.
105
+ * @param options - the Options object containing the configuration
106
+ * @param fieldName - the name of the field to parse as a boolean
107
+ * @param defaultValue - the default value to use in case the specified field is not present in Options
108
+ * @returns boolean the boolean value to be used for the configuration property
109
+ */
110
+ private static parseBoolean;
111
+ }
112
+ export {};
@@ -0,0 +1,151 @@
1
+ /**
2
+ * (C) Copyright IBM Corp. 2025.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import extend from 'extend';
17
+ import { validateInput } from '../utils/helpers';
18
+ import { buildUserAgent } from '../../lib/build-user-agent';
19
+ import { JwtTokenManager } from './jwt-token-manager';
20
+ import logger from '../../lib/logger';
21
+ /**
22
+ * Token Manager for Multi-Cloud Saas Platform (MCSP) V2 authentication.
23
+ *
24
+ * The McspV2TokenManager will invoke the MCSP token service's 'POST /api/2.0/\{scopeCollectionType\}/\{scopeId\}/apikeys/token'
25
+ * operation to obtain an MCSP access token for an apikey.
26
+ */
27
+ export class McspV2TokenManager extends JwtTokenManager {
28
+ /**
29
+ * Create a new McspV2TokenManager instance.
30
+ *
31
+ * @param options - Configuration options.
32
+ * This should be an object containing these fields:
33
+ * - url: (required) the endpoint URL for the CloudPakForData token service.
34
+ * - apikey: (optional) the API key used to obtain a bearer token (required if password is not specified).
35
+ * - scopeCollectionType: (required) The scope collection type of item(s). Valid values are: "accounts", "subscriptions", "services".
36
+ * - scopeId: (required) the scope identifier of item(s).
37
+ * - includeBuiltinActions: (optional) a flag to include builtin actions in the "actions" claim in the MCSP access token (default: false).
38
+ * - includeCustomActions: (optional) a flag to include custom actions in the "actions" claim in the MCSP access token (default: false).
39
+ * - includeRoles: (optional) a flag to include the "roles" claim in the MCSP access token (default: true).
40
+ * - prefixRoles: (optional) a flag to add a prefix with the scope level where the role is defined in the "roles" claim (default: false).
41
+ * - callerExtClaim: (optional) a map (object) containing keys and values to be injected into the access token as the "callerExt" claim.
42
+ * The keys used in this map must be enabled in the apikey by setting the "callerExtClaimNames" property when the apikey is created.
43
+ * This property is typically only used in scenarios involving an apikey with identityType `SERVICEID`.
44
+ * - disableSslVerification: (optional) a flag to disable verification of the token server's SSL certificate; defaults to false.
45
+ * - headers: (optional) a set of HTTP headers to be sent with each request to the token service.
46
+ *
47
+ * @throws Error: the input configuration failed validation
48
+ */
49
+ constructor(options) {
50
+ super(options);
51
+ this.requiredOptions = ['apikey', 'url', 'scopeCollectionType', 'scopeId'];
52
+ // This is the path associated with the operation used to obtain
53
+ // an access token from the MCSP token service (v2).
54
+ // The path parameter references must match the keys used in pathParams below.
55
+ this.PATH_TEMPLATE = '/api/2.0/{scopeCollectionType}/{scopeId}/apikeys/token';
56
+ // The name of the field (within the token-exchange operation's responseBody)
57
+ // that contains the access token.
58
+ this.tokenName = 'token';
59
+ // Validate the required properties.
60
+ validateInput(options, this.requiredOptions);
61
+ this.url = options.url;
62
+ this.apikey = options.apikey;
63
+ this.scopeCollectionType = options.scopeCollectionType;
64
+ this.scopeId = options.scopeId;
65
+ // Now parse/validate the optional properties.
66
+ this.includeBuiltinActions = McspV2TokenManager.parseBoolean(options, 'includeBuiltinActions', false);
67
+ this.includeCustomActions = McspV2TokenManager.parseBoolean(options, 'includeCustomActions', false);
68
+ this.includeRoles = McspV2TokenManager.parseBoolean(options, 'includeRoles', true);
69
+ this.prefixRoles = McspV2TokenManager.parseBoolean(options, 'prefixRoles', false);
70
+ if ('callerExtClaim' in options) {
71
+ const value = options.callerExtClaim;
72
+ if (typeof value === 'string') {
73
+ try {
74
+ this.callerExtClaim = JSON.parse(value);
75
+ }
76
+ catch (err) {
77
+ throw new Error(`An error occurred while parsing the callerExtClaim value '${value}': ${err.message}`);
78
+ }
79
+ }
80
+ else if (typeof value === 'object') {
81
+ this.callerExtClaim = value;
82
+ }
83
+ else {
84
+ throw new Error(`callerExtClaim must be a string or object, but was '${typeof value}'`);
85
+ }
86
+ }
87
+ this.userAgent = buildUserAgent('mcspv2-authenticator');
88
+ }
89
+ requestToken() {
90
+ const requiredHeaders = {
91
+ Accept: 'application/json',
92
+ 'Content-Type': 'application/json',
93
+ 'User-Agent': this.userAgent,
94
+ };
95
+ const requestHeaders = extend(true, {}, this.headers, requiredHeaders);
96
+ // The keys used here must match the path parameter references in PATH_TEMPLATE above.
97
+ const pathParams = {
98
+ scopeCollectionType: this.scopeCollectionType,
99
+ scopeId: this.scopeId,
100
+ };
101
+ // The keys used here must match the operation's query parameter names.
102
+ const queryParams = {
103
+ includeBuiltinActions: this.includeBuiltinActions,
104
+ includeCustomActions: this.includeCustomActions,
105
+ includeRoles: this.includeRoles,
106
+ prefixRolesWithDefinitionScope: this.prefixRoles,
107
+ };
108
+ const requestBody = {
109
+ apikey: this.apikey,
110
+ callerExtClaim: this.callerExtClaim || undefined,
111
+ };
112
+ const request = {
113
+ options: {
114
+ method: 'POST',
115
+ url: this.url + this.PATH_TEMPLATE,
116
+ body: requestBody,
117
+ path: pathParams,
118
+ qs: queryParams,
119
+ headers: requestHeaders,
120
+ rejectUnauthorized: !this.disableSslVerification,
121
+ },
122
+ };
123
+ logger.debug(`Invoking MCSP v2 token service operation: ${request.options.url}`);
124
+ return this.requestWrapperInstance.sendRequest(request).then((response) => {
125
+ logger.debug('Returned from MCSP v2 token service operation');
126
+ return response;
127
+ });
128
+ }
129
+ /**
130
+ * Parses the Options configuration property named by 'fieldName' as a boolean value.
131
+ * The value in the Options object could be either boolean or string and this function
132
+ * will do its best to parse it correctly.
133
+ * @param options - the Options object containing the configuration
134
+ * @param fieldName - the name of the field to parse as a boolean
135
+ * @param defaultValue - the default value to use in case the specified field is not present in Options
136
+ * @returns boolean the boolean value to be used for the configuration property
137
+ */
138
+ static parseBoolean(options, fieldName, defaultValue) {
139
+ let result = defaultValue;
140
+ if (fieldName in options) {
141
+ const value = options[fieldName];
142
+ if (typeof value === 'boolean') {
143
+ result = value;
144
+ }
145
+ else if (typeof value === 'string') {
146
+ result = value.toLowerCase() === 'true';
147
+ }
148
+ }
149
+ return result;
150
+ }
151
+ }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /**
3
- * (C) Copyright IBM Corp. 2020, 2024.
3
+ * (C) Copyright IBM Corp. 2020, 2025.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -131,7 +131,7 @@ export class TokenManager {
131
131
  * @returns Promise
132
132
  */
133
133
  requestToken() {
134
- const errMsg = '`requestToken` MUST be overridden by a subclass of TokenManagerV1.';
134
+ const errMsg = '`requestToken` MUST be overridden by a subclass of TokenManager.';
135
135
  const err = new Error(errMsg);
136
136
  logger.error(errMsg);
137
137
  return Promise.reject(err);
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2019, 2022.
2
+ * (C) Copyright IBM Corp. 2019, 2025.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2019, 2022.
2
+ * (C) Copyright IBM Corp. 2019, 2025.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Authenticator, BasicAuthenticator, BearerTokenAuthenticator, CloudPakForDataAuthenticator, IamAuthenticator, IamAssumeAuthenticator, ContainerAuthenticator, NoAuthAuthenticator, VpcInstanceAuthenticator, McspAuthenticator, } from '../authenticators';
16
+ import { Authenticator, BasicAuthenticator, BearerTokenAuthenticator, CloudPakForDataAuthenticator, IamAuthenticator, IamAssumeAuthenticator, ContainerAuthenticator, NoAuthAuthenticator, VpcInstanceAuthenticator, McspAuthenticator, McspV2Authenticator, } from '../authenticators';
17
17
  import { readExternalSources } from './read-external-sources';
18
18
  /**
19
19
  * Look for external configuration of authenticator.
@@ -90,6 +90,9 @@ export function getAuthenticatorFromEnvironment(serviceName) {
90
90
  else if (authType === Authenticator.AUTHTYPE_MCSP.toLowerCase()) {
91
91
  authenticator = new McspAuthenticator(credentials);
92
92
  }
93
+ else if (authType === Authenticator.AUTHTYPE_MCSPV2.toLowerCase()) {
94
+ authenticator = new McspV2Authenticator(credentials);
95
+ }
93
96
  else {
94
97
  throw new Error(`Invalid value for AUTH_TYPE: ${authType}`);
95
98
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2014, 2024.
2
+ * (C) Copyright IBM Corp. 2014, 2025.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  /**
12
- * (C) Copyright IBM Corp. 2014, 2024.
12
+ * (C) Copyright IBM Corp. 2014, 2025.
13
13
  *
14
14
  * Licensed under the Apache License, Version 2.0 (the "License");
15
15
  * you may not use this file except in compliance with the License.
@@ -111,10 +111,15 @@ export class RequestWrapper {
111
111
  * @returns the string representation of the request
112
112
  */
113
113
  formatAxiosRequest(request) {
114
- const { method, url, data, headers } = request;
114
+ const { method, url, data, headers, params } = request;
115
+ let queryString = stringify(params);
116
+ if (queryString) {
117
+ queryString = `?${queryString}`;
118
+ }
115
119
  const headersOutput = this.formatAxiosHeaders(headers);
116
120
  const body = this.formatAxiosBody(data);
117
- const output = `${(method || '??').toUpperCase()} ${url || '??'}\n${headersOutput}\n${body}`;
121
+ const urlStr = url ? url + queryString : '??';
122
+ const output = `${(method || '??').toUpperCase()} ${urlStr}\n${headersOutput}\n${body}`;
118
123
  return redactSecrets(output);
119
124
  }
120
125
  /**