public override async Task <GetAuthenticationCredentialsResponse> HandleRequestAsync(GetAuthenticationCredentialsRequest request, CancellationToken cancellationToken) { var forceCanShowDialogTo = EnvUtil.ForceCanShowDialogTo(); var canShowDialog = request.CanShowDialog; if (forceCanShowDialogTo.HasValue) { Logger.Verbose(string.Format(Resources.ForcingCanShowDialogFromTo, request.CanShowDialog, forceCanShowDialogTo.Value)); canShowDialog = forceCanShowDialogTo.Value; } Uri authority = await authUtil.GetAadAuthorityUriAsync(request.Uri, cancellationToken); Verbose(string.Format(Resources.AdalUsingAuthority, authority)); IEnumerable <IBearerTokenProvider> bearerTokenProviders = bearerTokenProvidersFactory.Get(authority.ToString()); cancellationToken.ThrowIfCancellationRequested(); // Try each bearer token provider (e.g. ADAL cache, ADAL WIA, ADAL UI, ADAL DeviceCode) in order. // Only consider it successful if the bearer token can be exchanged for an Azure DevOps token. foreach (IBearerTokenProvider bearerTokenProvider in bearerTokenProviders) { bool shouldRun = bearerTokenProvider.ShouldRun(request.IsRetry, request.IsNonInteractive, canShowDialog); if (!shouldRun) { Verbose(string.Format(Resources.NotRunningBearerTokenProvider, bearerTokenProvider.Name)); continue; } Verbose(string.Format(Resources.AttemptingToAcquireBearerTokenUsingProvider, bearerTokenProvider.Name)); string bearerToken = null; try { bearerToken = await bearerTokenProvider.GetTokenAsync(request.Uri, cancellationToken); } catch (Exception ex) { Verbose(string.Format(Resources.BearerTokenProviderException, bearerTokenProvider.Name, ex)); continue; } if (string.IsNullOrWhiteSpace(bearerToken)) { Verbose(string.Format(Resources.BearerTokenProviderReturnedNull, bearerTokenProvider.Name)); continue; } Info(string.Format(Resources.AcquireBearerTokenSuccess, bearerTokenProvider.Name)); Info(Resources.ExchangingBearerTokenForSessionToken); try { string sessionToken = await vstsSessionTokenProvider.GetAzureDevOpsSessionTokenFromBearerToken(request, bearerToken, bearerTokenProvider.Interactive, cancellationToken); if (!string.IsNullOrWhiteSpace(sessionToken)) { Verbose(string.Format(Resources.VSTSSessionTokenCreated, request.Uri.AbsoluteUri)); return(new GetAuthenticationCredentialsResponse( Username, sessionToken, message: null, authenticationTypes: new List <string>() { "Basic" }, responseCode: MessageResponseCode.Success)); } } catch (Exception e) { Verbose(string.Format(Resources.VSTSCreateSessionException, request.Uri.AbsoluteUri, e.Message, e.StackTrace)); } } Verbose(string.Format(Resources.VSTSCredentialsNotFound, request.Uri.AbsoluteUri)); return(null); }