Skip to content

Commit 4f2f789

Browse files
committed
feat: carry disable_ssl_verification through to token managers
1 parent bd902eb commit 4f2f789

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

auth/icp-token-manager.ts

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type Options = {
2323
accessToken?: string;
2424
username?: string;
2525
password?: string;
26+
disableSslVerification?: boolean;
2627
}
2728

2829
// this interface is a representation of the response
@@ -54,6 +55,7 @@ export class Icp4dTokenManagerV1 extends JwtTokenManager {
5455
* @param {String} options.password
5556
* @param {String} options.accessToken - user-managed access token
5657
* @param {String} options.url - URL for the ICP4D cluster
58+
* @param {Boolean} options.disableSslVerification - disable SSL verification for token request
5759
* @constructor
5860
*/
5961
constructor(options: Options) {
@@ -98,6 +100,7 @@ export class Icp4dTokenManagerV1 extends JwtTokenManager {
98100
Authorization:
99101
this.computeBasicAuthHeader(this.username, this.password),
100102
},
103+
rejectUnauthorized: this.rejectUnauthorized,
101104
}
102105
};
103106
sendRequest(parameters, callback);

auth/jwt-token-manager.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ function getCurrentTime(): number {
2525
export type Options = {
2626
accessToken?: string;
2727
url?: string;
28+
disableSslVerification?: boolean;
2829
}
2930

3031
export class JwtTokenManager {
3132
protected url: string;
3233
protected tokenName: string;
3334
protected userAccessToken: string;
35+
protected rejectUnauthorized: boolean;
3436
private tokenInfo: any;
3537
private timeToLive: number;
3638
private expireTime: number;
@@ -42,7 +44,8 @@ export class JwtTokenManager {
4244
*
4345
* @param {Object} options
4446
* @param {String} options.url - url of the api to retrieve tokens from
45-
* @param {String} options.accessToken
47+
* @param {String} [options.accessToken] - user-managed access token
48+
* @param {String} [options.disableSslVerification] - pass in to disable SSL verification on requests. defaults to false
4649
* @constructor
4750
*/
4851
constructor(options: Options) {
@@ -53,9 +56,12 @@ export class JwtTokenManager {
5356
if (options.url) {
5457
this.url = options.url;
5558
}
59+
5660
if (options.accessToken) {
5761
this.userAccessToken = options.accessToken;
5862
}
63+
64+
this.rejectUnauthorized = !options.disableSslVerification;
5965
}
6066

6167
/**

iam-token-manager/v1.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export type Options = {
4242
iamAccessToken?: string;
4343
iamClientId?: string;
4444
iamClientSecret?: string;
45+
disableSslVerification?: boolean;
4546
}
4647

4748
// this interface is a representation of the response
@@ -69,6 +70,7 @@ export class IamTokenManagerV1 extends JwtTokenManager {
6970
* @param {String} options.iamApikey
7071
* @param {String} options.iamAccessToken
7172
* @param {String} options.iamUrl - url of the iam api to retrieve tokens from
73+
* @param {Boolean} options.disableSslVerification - disable SSL verification for token request
7274
* @constructor
7375
*/
7476
constructor(options: Options) {
@@ -151,7 +153,8 @@ export class IamTokenManagerV1 extends JwtTokenManager {
151153
grant_type: 'urn:ibm:params:oauth:grant-type:apikey',
152154
apikey: this.iamApikey,
153155
response_type: 'cloud_iam'
154-
}
156+
},
157+
rejectUnauthorized: this.rejectUnauthorized,
155158
}
156159
};
157160
sendRequest(parameters, callback);

lib/base_service.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import extend = require('extend');
1818
import vcapServices = require('vcap_services');
19-
import { IcpTokenManagerV1 } from '../auth/icp-token-manager';
19+
import { Icp4dTokenManagerV1 } from '../auth/icp-token-manager';
2020
import { IamTokenManagerV1 } from '../iam-token-manager/v1';
2121
import { stripTrailingSlash } from './helper';
2222
import { readCredentialsFile } from './read-credentials-file';
@@ -178,34 +178,38 @@ export class BaseService {
178178
_options.authentication_type = _options.authentication_type.toLowerCase();
179179
}
180180

181+
// rejectUnauthorized should only be false if disable_ssl_verification is true
182+
// used to disable ssl checking for icp
183+
this._options.rejectUnauthorized = !options.disable_ssl_verification;
184+
181185
if (_options.authentication_type === 'iam' || hasIamCredentials(_options)) {
182186
this.tokenManager = new IamTokenManagerV1({
183187
iamApikey: _options.iam_apikey || _options.password,
184188
accessToken: _options.iam_access_token,
185189
url: _options.iam_url,
186190
iamClientId: _options.iam_client_id,
187-
iamClientSecret: _options.iam_client_secret
191+
iamClientSecret: _options.iam_client_secret,
192+
disableSslVerification: options.disable_ssl_verification,
188193
});
189194
} else if (usesBasicForIam(_options)) {
190195
this.tokenManager = new IamTokenManagerV1({
191196
iamApikey: _options.password,
192197
url: _options.iam_url,
193198
iamClientId: _options.iam_client_id,
194-
iamClientSecret: _options.iam_client_secret
199+
iamClientSecret: _options.iam_client_secret,
200+
disableSslVerification: options.disable_ssl_verification,
195201
});
196202
} else if (isForICP4D(_options)) {
197-
this.tokenManager = new IcpTokenManagerV1({
203+
this.tokenManager = new Icp4dTokenManagerV1({
198204
url: _options.url,
199205
username: _options.username,
200206
password: _options.password,
201-
accessToken: _options.icp_access_token
207+
accessToken: _options.icp_access_token,
208+
disableSslVerification: options.disable_ssl_verification,
202209
});
203210
} else {
204211
this.tokenManager = null;
205212
}
206-
// rejectUnauthorized should only be false if disable_ssl_verification is true
207-
// used to disable ssl checking for icp
208-
this._options.rejectUnauthorized = !options.disable_ssl_verification;
209213
}
210214

211215
/**
@@ -260,13 +264,15 @@ export class BaseService {
260264
if (this.tokenManager) {
261265
this.tokenManager.setAccessToken(access_token);
262266
} else if (this._options.authentication_type === 'icp4d') {
263-
this.tokenManager = new IcpTokenManagerV1({
267+
this.tokenManager = new Icp4dTokenManagerV1({
264268
accessToken: access_token,
265-
url: this._options.url
269+
url: this._options.url,
270+
disableSslVerification: this._options.disable_ssl_verification,
266271
});
267272
} else {
268273
this.tokenManager = new IamTokenManagerV1({
269-
accessToken: access_token
274+
accessToken: access_token,
275+
disableSslVerification: this._options.disable_ssl_verification,
270276
});
271277
}
272278
}

0 commit comments

Comments
 (0)