@@ -59,7 +59,7 @@ public bool IsSupported(InputArguments input)
5959 return false ;
6060 }
6161
62- // We do not support unencrypted HTTP communications to Azure Repos,
62+ // We do not recommend unencrypted HTTP communications to Azure Repos,
6363 // but we report `true` here for HTTP so that we can show a helpful
6464 // error message for the user in `CreateCredentialAsync`.
6565 return input . TryGetHostAndPort ( out string hostName , out _ )
@@ -208,16 +208,22 @@ protected override void ReleaseManagedResources()
208208 base . ReleaseManagedResources ( ) ;
209209 }
210210
211- private async Task < ICredential > GeneratePersonalAccessTokenAsync ( InputArguments input )
211+ private void ThrowIfUnsafeRemote ( InputArguments input )
212212 {
213- ThrowIfDisposed ( ) ;
214-
215- // We should not allow unencrypted communication and should inform the user
216- if ( StringComparer . OrdinalIgnoreCase . Equals ( input . Protocol , "http" ) )
213+ if ( ! _context . Settings . AllowUnsafeRemotes &&
214+ StringComparer . OrdinalIgnoreCase . Equals ( input . Protocol , "http" ) )
217215 {
218216 throw new Trace2Exception ( _context . Trace2 ,
219- "Unencrypted HTTP is not supported for Azure Repos. Ensure the repository remote URL is using HTTPS." ) ;
217+ "Unencrypted HTTP is not recommended for Azure Repos. " +
218+ "Ensure the repository remote URL is using HTTPS " +
219+ $ "or see { Constants . HelpUrls . GcmUnsafeRemotes } about how to allow unsafe remotes.") ;
220220 }
221+ }
222+
223+ private async Task < ICredential > GeneratePersonalAccessTokenAsync ( InputArguments input )
224+ {
225+ ThrowIfDisposed ( ) ;
226+ ThrowIfUnsafeRemote ( input ) ;
221227
222228 Uri remoteUserUri = input . GetRemoteUri ( includeUser : true ) ;
223229 Uri orgUri = UriHelpers . CreateOrganizationUri ( remoteUserUri , out _ ) ;
@@ -257,16 +263,11 @@ private async Task<ICredential> GeneratePersonalAccessTokenAsync(InputArguments
257263
258264 private async Task < IMicrosoftAuthenticationResult > GetAzureAccessTokenAsync ( InputArguments input )
259265 {
266+ ThrowIfUnsafeRemote ( input ) ;
267+
260268 Uri remoteWithUserUri = input . GetRemoteUri ( includeUser : true ) ;
261269 string userName = input . UserName ;
262270
263- // We should not allow unencrypted communication and should inform the user
264- if ( StringComparer . OrdinalIgnoreCase . Equals ( remoteWithUserUri . Scheme , "http" ) )
265- {
266- throw new Trace2Exception ( _context . Trace2 ,
267- "Unencrypted HTTP is not supported for Azure Repos. Ensure the repository remote URL is using HTTPS." ) ;
268- }
269-
270271 Uri orgUri = UriHelpers . CreateOrganizationUri ( remoteWithUserUri , out string orgName ) ;
271272
272273 _context . Trace . WriteLine ( $ "Determining Microsoft Authentication authority for Azure DevOps organization '{ orgName } '...") ;
0 commit comments