@@ -435,39 +435,49 @@ private HttpClient GetHttpClient(TargetUri targetUri, HttpMessageHandler handler
435
435
switch ( options . Authorization )
436
436
{
437
437
case Token token :
438
+ {
439
+ // Different types of tokens are packed differently.
440
+ switch ( token . Type )
438
441
{
439
- // Different types of tokens are packed differently.
440
- switch ( token . Type )
442
+ case TokenType . AzureAccess :
443
+ case TokenType . BitbucketAccess :
441
444
{
442
- case TokenType . AzureAccess :
443
- case TokenType . BitbucketAccess :
444
- case TokenType . Personal :
445
- {
446
- // ADAL access tokens are packed into the Authorization header.
447
- httpClient . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token . Value ) ;
448
- }
449
- break ;
450
-
451
- case TokenType . AzureFederated :
452
- {
453
- // Federated authentication tokens are sent as cookie(s).
454
- httpClient . DefaultRequestHeaders . Add ( "Cookie" , token . Value ) ;
455
- }
456
- break ;
457
-
458
- default :
459
- Trace . WriteLine ( "! unsupported token type, not appending an authentication header to the request." ) ;
460
- break ;
445
+ // ADAL access tokens are packed into the Authorization header.
446
+ httpClient . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token . Value ) ;
461
447
}
448
+ break ;
449
+
450
+ case TokenType . AzureFederated :
451
+ {
452
+ // Federated authentication tokens are sent as cookie(s).
453
+ httpClient . DefaultRequestHeaders . Add ( "Cookie" , token . Value ) ;
454
+ }
455
+ break ;
456
+
457
+ case TokenType . Personal :
458
+ {
459
+ // Personal access tokens are designed to treated like credentials,
460
+ // so treat them like credentials.
461
+ var credentials = ( Credential ) token ;
462
+
463
+ // Credentials are packed into the 'Authorization' header as a base64 encoded pair.
464
+ httpClient . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Basic" , credentials . ToBase64String ( ) ) ;
465
+ }
466
+ break ;
467
+
468
+ default :
469
+ Trace . WriteLine ( "! unsupported token type, not appending an authentication header to the request." ) ;
470
+ break ;
462
471
}
463
- break ;
472
+ }
473
+ break ;
464
474
465
475
case Credential credentials :
466
- {
467
- // Credentials are packed into the 'Authorization' header as a base64 encoded pair.
468
- httpClient . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Basic" , credentials . ToBase64String ( ) ) ;
469
- }
470
- break ;
476
+ {
477
+ // Credentials are packed into the 'Authorization' header as a base64 encoded pair.
478
+ httpClient . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Basic" , credentials . ToBase64String ( ) ) ;
479
+ }
480
+ break ;
471
481
}
472
482
}
473
483
}
@@ -491,7 +501,7 @@ private static IWebProxy GetHttpWebProxy(TargetUri targetUri)
491
501
492
502
if ( proxyUri != null )
493
503
{
494
- WebProxy proxy = new WebProxy ( proxyUri ) { UseDefaultCredentials = true } ;
504
+ var proxy = new WebProxy ( proxyUri ) { UseDefaultCredentials = true } ;
495
505
496
506
// check if the user has specified authentications (comes as UserInfo)
497
507
if ( ! string . IsNullOrWhiteSpace ( proxyUri . UserInfo ) && proxyUri . UserInfo . Length > 1 )
@@ -504,7 +514,7 @@ private static IWebProxy GetHttpWebProxy(TargetUri targetUri)
504
514
string userName = proxyUri . UserInfo . Substring ( 0 , tokenIndex ) ;
505
515
string password = proxyUri . UserInfo . Substring ( tokenIndex + 1 ) ;
506
516
507
- NetworkCredential proxyCreds = new NetworkCredential ( userName , password ) ;
517
+ var proxyCreds = new NetworkCredential ( userName , password ) ;
508
518
509
519
proxy . UseDefaultCredentials = false ;
510
520
proxy . Credentials = proxyCreds ;
0 commit comments