@@ -65,7 +65,7 @@ public bool IsSupported(HttpResponseMessage response)
65
65
}
66
66
67
67
// Identify Bitbucket on-prem instances from the HTTP response using the Atlassian specific header X-AREQUESTID
68
- var supported = response . Headers . Contains ( "X-AREQUESTID" ) ;
68
+ var supported = response . Headers . Contains ( "X-AREQUESTID" ) ;
69
69
70
70
_context . Trace . WriteLine ( $ "Host is{ ( supported ? null : "n't" ) } supported as Bitbucket") ;
71
71
@@ -94,8 +94,8 @@ private static void ValidateTargetUri(InputArguments input)
94
94
95
95
private async Task < ICredential > GetStoredCredentials ( InputArguments input )
96
96
{
97
- if ( _context . Settings . TryGetSetting ( BitbucketConstants . EnvironmentVariables . AlwaysRefreshCredentials ,
98
- Constants . GitConfiguration . Credential . SectionName , BitbucketConstants . GitConfiguration . Credential . AlwaysRefreshCredentials ,
97
+ if ( _context . Settings . TryGetSetting ( BitbucketConstants . EnvironmentVariables . AlwaysRefreshCredentials ,
98
+ Constants . GitConfiguration . Credential . SectionName , BitbucketConstants . GitConfiguration . Credential . AlwaysRefreshCredentials ,
99
99
out string alwaysRefreshCredentials ) && alwaysRefreshCredentials . ToBooleanyOrDefault ( false ) )
100
100
{
101
101
_context . Trace . WriteLine ( $ "Ignore stored credentials") ;
@@ -110,14 +110,15 @@ private async Task<ICredential> GetStoredCredentials(InputArguments input)
110
110
111
111
if ( credentials == null )
112
112
{
113
- _context . Trace . WriteLine ( $ " Found none ") ;
113
+ _context . Trace . WriteLine ( $ "No stored credentials found ") ;
114
114
return null ;
115
115
}
116
116
117
- _context . Trace . WriteLineSecrets ( $ " Found credentials: { credentials . Account } /{{0}}", new object [ ] { credentials . Password } ) ;
118
-
119
- //check credentials are still valid
120
- if ( ! await ValidateCredentialsWork ( input , credentials , GetSupportedAuthenticationModes ( targetUri ) ) ) {
117
+ _context . Trace . WriteLineSecrets ( $ "Found stored credentials: { credentials . Account } /{{0}}", new object [ ] { credentials . Password } ) ;
118
+
119
+ // Check credentials are still valid
120
+ if ( ! await ValidateCredentialsWork ( input , credentials , GetSupportedAuthenticationModes ( targetUri ) ) )
121
+ {
121
122
return null ;
122
123
}
123
124
@@ -139,7 +140,7 @@ private async Task<ICredential> GetRefreshedCredentials(InputArguments input)
139
140
ICredential refreshToken = SupportsOAuth ( authModes ) ? _context . CredentialStore . Get ( refreshTokenService , input . UserName ) : null ;
140
141
if ( refreshToken is null )
141
142
{
142
- _context . Trace . WriteLine ( $ " Found none ") ;
143
+ _context . Trace . WriteLine ( $ "No stored refresh token found ") ;
143
144
// There is no refresh token either because this is a non-2FA enabled account (where OAuth is not
144
145
// required), or because we previously erased the RT.
145
146
@@ -156,7 +157,7 @@ private async Task<ICredential> GetRefreshedCredentials(InputArguments input)
156
157
{
157
158
return basicCredentials ;
158
159
}
159
-
160
+
160
161
// Fall through to the start of the interactive OAuth authentication flow
161
162
}
162
163
@@ -178,7 +179,7 @@ private async Task<ICredential> GetRefreshedCredentials(InputArguments input)
178
179
}
179
180
else
180
181
{
181
- _context . Trace . WriteLine ( $ " Found refresh token: { refreshToken } " ) ;
182
+ _context . Trace . WriteLineSecrets ( $ "Found stored refresh token: {{0}}" , new object [ ] { refreshToken } ) ;
182
183
183
184
// It's very likely that any access token expired between the last time we used/stored it.
184
185
// To ensure the AT is as 'fresh' as it can be, always first try to use the refresh token
@@ -379,7 +380,7 @@ private async Task<string> ResolveBasicAuthUserNameAsync(string username, string
379
380
380
381
private async Task < bool > RequiresTwoFactorAuthenticationAsync ( ICredential credentials , AuthenticationModes authModes )
381
382
{
382
- _context . Trace . WriteLineSecrets ( $ "Check if 2FA si required for credentials ({ credentials . Account } /{{0}}) { authModes } ...", new object [ ] { credentials . Password } ) ;
383
+ _context . Trace . WriteLineSecrets ( $ "Check if 2FA si required for credentials ({ credentials . Account } /{{0}}) { authModes } ...", new object [ ] { credentials . Password } ) ;
383
384
384
385
if ( ! SupportsOAuth ( authModes ) )
385
386
{
@@ -407,7 +408,7 @@ private async Task<bool> RequiresTwoFactorAuthenticationAsync(ICredential creden
407
408
}
408
409
}
409
410
410
- private async Task < bool > ValidateCredentialsWork ( InputArguments input , ICredential credentials , AuthenticationModes authModes )
411
+ private async Task < bool > ValidateCredentialsWork ( InputArguments input , ICredential credentials , AuthenticationModes authModes )
411
412
{
412
413
if ( credentials == null )
413
414
{
@@ -419,7 +420,7 @@ private async Task<bool> ValidateCredentialsWork(InputArguments input, ICredenti
419
420
// This would be more efficient than having to make REST API calls to check.
420
421
421
422
var targetUri = input . GetRemoteUri ( ) ;
422
- _context . Trace . WriteLineSecrets ( $ "Validate credentials ({ credentials . Account } /{{0}}) are fresh for { targetUri } ...", new object [ ] { credentials . Password } ) ;
423
+ _context . Trace . WriteLineSecrets ( $ "Validate credentials ({ credentials . Account } /{{0}}) are fresh for { targetUri } ...", new object [ ] { credentials . Password } ) ;
423
424
424
425
if ( ! IsBitbucketOrg ( targetUri ) )
425
426
{
@@ -440,7 +441,7 @@ private async Task<bool> ValidateCredentialsWork(InputArguments input, ICredenti
440
441
_context . Trace . WriteLine ( "Validated existing credentials using OAuth" ) ;
441
442
return true ;
442
443
}
443
- catch ( Exception )
444
+ catch ( Exception )
444
445
{
445
446
_context . Trace . WriteLine ( "Failed to validate existing credentials using OAuth" ) ;
446
447
}
@@ -454,7 +455,7 @@ private async Task<bool> ValidateCredentialsWork(InputArguments input, ICredenti
454
455
_context . Trace . WriteLine ( "Validated existing credentials using BasicAuth" ) ;
455
456
return true ;
456
457
}
457
- catch ( Exception )
458
+ catch ( Exception )
458
459
{
459
460
_context . Trace . WriteLine ( "Failed to validate existing credentials using Basic Auth" ) ;
460
461
return false ;
@@ -475,7 +476,7 @@ private static string GetRefreshTokenServiceName(InputArguments input)
475
476
476
477
// The refresh token key never includes the path component.
477
478
// Instead we use the path component to specify this is the "refresh_token".
478
- Uri uri = new UriBuilder ( baseUri ) { Path = "/refresh_token" } . Uri ;
479
+ Uri uri = new UriBuilder ( baseUri ) { Path = "/refresh_token" } . Uri ;
479
480
480
481
return uri . AbsoluteUri . TrimEnd ( '/' ) ;
481
482
}
0 commit comments