@@ -49,6 +49,7 @@ const InternalOpenIDError = require('./errors/internalopeniderror');
49
49
const Log = require ( './logging' ) . getLogger ;
50
50
const Metadata = require ( './metadata' ) . Metadata ;
51
51
const OAuth2 = require ( 'oauth' ) . OAuth2 ;
52
+ const HttpsProxyAgent = require ( 'https-proxy-agent' ) ;
52
53
const SessionContentHandler = require ( './sessionContentHandler' ) . SessionContentHandler ;
53
54
const CookieContentHandler = require ( './cookieContentHandler' ) . CookieContentHandler ;
54
55
const Validator = require ( './validator' ) . Validator ;
@@ -285,6 +286,10 @@ function onProfileLoaded(strategy, args) {
285
286
* (2) must be a positive integer
286
287
* (3) Description:
287
288
* the clock skew (in seconds) allowed in token validation, default value is CLOCK_SKEW
289
+ *
290
+ * - `proxy` (1) Optional
291
+ * (2) Description:
292
+ * the configuration parameters for HttpsProxyAgent
288
293
*
289
294
* Examples:
290
295
*
@@ -476,7 +481,7 @@ function Strategy(options, verify) {
476
481
/****************************************************************************************
477
482
* Take care of scope
478
483
***************************************************************************************/
479
- // make scope an array
484
+ // make scope an array
480
485
if ( ! options . scope )
481
486
options . scope = [ ] ;
482
487
if ( ! Array . isArray ( options . scope ) )
@@ -601,9 +606,9 @@ Strategy.prototype.authenticate = function authenticateStrategy(req, options) {
601
606
var response = options && options . response || req . res ;
602
607
603
608
// 'params': items we get from the request or metadata, such as id_token, code, policy, metadata, cacheKey, etc
604
- var params = { 'tenantIdOrName' : tenantIdOrName , 'extraAuthReqQueryParams' : extraAuthReqQueryParams , 'extraTokenReqQueryParams' : extraTokenReqQueryParams } ;
609
+ var params = { 'proxy' : self . _options . proxy , ' tenantIdOrName' : tenantIdOrName , 'extraAuthReqQueryParams' : extraAuthReqQueryParams , 'extraTokenReqQueryParams' : extraTokenReqQueryParams } ;
605
610
// 'oauthConfig': items needed for oauth flow (like redirection, code redemption), such as token_endpoint, userinfo_endpoint, etc
606
- var oauthConfig = { 'resource' : resource , 'customState' : customState , 'domain_hint' : domain_hint , 'login_hint' : login_hint , 'prompt' : prompt , 'response' : response } ;
611
+ var oauthConfig = { 'proxy' : self . _options . proxy , ' resource' : resource , 'customState' : customState , 'domain_hint' : domain_hint , 'login_hint' : login_hint , 'prompt' : prompt , 'response' : response } ;
607
612
// 'optionsToValidate': items we need to validate id_token against, such as issuer, audience, etc
608
613
var optionsToValidate = { } ;
609
614
@@ -672,7 +677,7 @@ Strategy.prototype.authenticate = function authenticateStrategy(req, options) {
672
677
* @param {Object } req
673
678
* @param {Object } next
674
679
*/
675
- Strategy . prototype . collectInfoFromReq = function ( params , req , next , response ) {
680
+ Strategy . prototype . collectInfoFromReq = function ( params , req , next , response ) {
676
681
const self = this ;
677
682
678
683
// the things we will put into 'params':
@@ -858,7 +863,7 @@ Strategy.prototype.setOptions = function setOptions(params, oauthConfig, options
858
863
}
859
864
860
865
// for B2C, verify the endpoints in oauthConfig has the correct policy
861
- if ( self . _options . isB2C ) {
866
+ if ( self . _options . isB2C ) {
862
867
var policyChecker = ( endpoint , policy ) => {
863
868
var u = { } ;
864
869
try {
@@ -956,7 +961,7 @@ Strategy.prototype._idTokenHandler = function idTokenHandler(params, optionsToVa
956
961
var decrypted_token ;
957
962
958
963
return jwe . decrypt ( id_token , optionsToValidate . jweKeyStore , log , ( err , decrypted_token ) => {
959
- if ( err )
964
+ if ( err )
960
965
return next ( err ) ;
961
966
962
967
params . id_token = decrypted_token ;
@@ -1462,7 +1467,7 @@ Strategy.prototype._getAccessTokenBySecretOrAssertion = function getAccessTokenB
1462
1467
return next ( err ) ;
1463
1468
else
1464
1469
post_params [ 'client_assertion' ] = assertion ;
1465
- } ) ;
1470
+ } ) ;
1466
1471
1467
1472
if ( self . _options . loggingNoPII )
1468
1473
log . info ( 'In _getAccessTokenBySecretOrAssertion: we created a client assertion' ) ;
@@ -1480,7 +1485,7 @@ Strategy.prototype._getAccessTokenBySecretOrAssertion = function getAccessTokenB
1480
1485
var results ;
1481
1486
try {
1482
1487
results = JSON . parse ( data ) ;
1483
- } catch ( e ) {
1488
+ } catch ( e ) {
1484
1489
results = querystring . parse ( data ) ;
1485
1490
}
1486
1491
callback ( null , results ) ;
@@ -1519,6 +1524,11 @@ var createOauth2Instance = function(oauthConfig) {
1519
1524
libraryVersionParameterName : libraryVersion } // customHeaders
1520
1525
) ;
1521
1526
1527
+ if ( oauthConfig . proxy ) {
1528
+ // if user has specified proxy settings instantiate agent
1529
+ oauth2 . setAgent ( new HttpsProxyAgent ( oauthConfig . proxy ) ) ;
1530
+ }
1531
+
1522
1532
return oauth2 ;
1523
1533
} ;
1524
1534
0 commit comments