@@ -59,7 +59,7 @@ public bool IsSupported(InputArguments input)
59
59
return false ;
60
60
}
61
61
62
- // We do not support unencrypted HTTP communications to Azure Repos,
62
+ // We do not recommend unencrypted HTTP communications to Azure Repos,
63
63
// but we report `true` here for HTTP so that we can show a helpful
64
64
// error message for the user in `CreateCredentialAsync`.
65
65
return input . TryGetHostAndPort ( out string hostName , out _ )
@@ -208,16 +208,22 @@ protected override void ReleaseManagedResources()
208
208
base . ReleaseManagedResources ( ) ;
209
209
}
210
210
211
- private async Task < ICredential > GeneratePersonalAccessTokenAsync ( InputArguments input )
211
+ private void ThrowIfUnsafeRemote ( InputArguments input )
212
212
{
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" ) )
217
215
{
218
216
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.") ;
220
220
}
221
+ }
222
+
223
+ private async Task < ICredential > GeneratePersonalAccessTokenAsync ( InputArguments input )
224
+ {
225
+ ThrowIfDisposed ( ) ;
226
+ ThrowIfUnsafeRemote ( input ) ;
221
227
222
228
Uri remoteUserUri = input . GetRemoteUri ( includeUser : true ) ;
223
229
Uri orgUri = UriHelpers . CreateOrganizationUri ( remoteUserUri , out _ ) ;
@@ -257,16 +263,11 @@ private async Task<ICredential> GeneratePersonalAccessTokenAsync(InputArguments
257
263
258
264
private async Task < IMicrosoftAuthenticationResult > GetAzureAccessTokenAsync ( InputArguments input )
259
265
{
266
+ ThrowIfUnsafeRemote ( input ) ;
267
+
260
268
Uri remoteWithUserUri = input . GetRemoteUri ( includeUser : true ) ;
261
269
string userName = input . UserName ;
262
270
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
-
270
271
Uri orgUri = UriHelpers . CreateOrganizationUri ( remoteWithUserUri , out string orgName ) ;
271
272
272
273
_context . Trace . WriteLine ( $ "Determining Microsoft Authentication authority for Azure DevOps organization '{ orgName } '...") ;
0 commit comments