@@ -51,15 +51,16 @@ public bool IsSupported(InputArguments input)
51
51
52
52
public async Task < ICredential > GetCredentialAsync ( InputArguments input )
53
53
{
54
+ // Compute the target URI
55
+ Uri targetUri = GetTargetUri ( input ) ;
56
+
54
57
// We should not allow unencrypted communication and should inform the user
55
- if ( StringComparer . OrdinalIgnoreCase . Equals ( input . Protocol , "http" ) )
58
+ if ( StringComparer . OrdinalIgnoreCase . Equals ( input . Protocol , "http" )
59
+ && targetUri . Host . Equals ( BitbucketConstants . BitbucketBaseUrlHost ) )
56
60
{
57
61
throw new Exception ( "Unencrypted HTTP is not supported for Bitbucket. Ensure the repository remote URL is using HTTPS." ) ;
58
62
}
59
63
60
- // Compute the target URI
61
- Uri targetUri = GetTargetUri ( input ) ;
62
-
63
64
// Try and get the username specified in the remote URL if any
64
65
string targetUriUser = targetUri . GetUserName ( ) ;
65
66
@@ -93,7 +94,7 @@ public async Task<ICredential> GetCredentialAsync(InputArguments input)
93
94
// or we have a freshly captured user/pass. Regardless, we must check if these credentials
94
95
// pass and two-factor requirement on the account.
95
96
_context . Trace . WriteLine ( "Checking if two-factor requirements for stored credentials..." ) ;
96
- bool requires2Fa = await RequiresTwoFactorAuthenticationAsync ( credential ) ;
97
+ bool requires2Fa = await RequiresTwoFactorAuthenticationAsync ( credential , targetUri ) ;
97
98
if ( ! requires2Fa )
98
99
{
99
100
_context . Trace . WriteLine ( "Two-factor requirement passed with stored credentials" ) ;
@@ -220,8 +221,14 @@ private async Task<string> ResolveOAuthUserNameAsync(string accessToken)
220
221
throw new Exception ( $ "Failed to resolve username. HTTP: { result . StatusCode } ") ;
221
222
}
222
223
223
- private async Task < bool > RequiresTwoFactorAuthenticationAsync ( ICredential credentials )
224
+ private async Task < bool > RequiresTwoFactorAuthenticationAsync ( ICredential credentials , Uri targetUri )
224
225
{
226
+ if ( ! targetUri . Host . Equals ( BitbucketConstants . BitbucketBaseUrlHost ) )
227
+ {
228
+ // BBS
229
+ return false ;
230
+ }
231
+
225
232
RestApiResult < UserInfo > result = await _bitbucketApi . GetUserInformationAsync ( credentials . UserName , credentials . Password , false ) ;
226
233
switch ( result . StatusCode )
227
234
{
0 commit comments