/// <summary> /// This method is responsible for retrieving either cached credentials /// or forcing a prompt if we need the user to give us new credentials. /// </summary> private async Task <CredentialResponse> PromptForCredentialsAsync(Uri uri, CancellationToken cancellationToken) { const __VsWebProxyState oldState = __VsWebProxyState.VsWebProxyState_PromptForCredentials; var newState = (uint)__VsWebProxyState.VsWebProxyState_NoCredentials; int result = 0; cancellationToken.ThrowIfCancellationRequested(); await NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); result = _webProxyService.PrepareWebProxy(uri.OriginalString, (uint)oldState, out newState, fOkToPrompt: 1); }); // If result is anything but 0 that most likely means that there was an error // so we will null out the DefaultWebProxy.Credentials so that we don't get // invalid credentials stored for subsequent requests. if (result != 0 || newState == (uint)__VsWebProxyState.VsWebProxyState_Abort) { // The user might have clicked cancel, so we don't want to use the currently set // credentials if they are wrong. return(new CredentialResponse(CredentialStatus.UserCanceled)); } // Get the new credentials from the proxy instance return(new CredentialResponse(WebRequest.DefaultWebProxy.Credentials)); }
/// <summary> /// This method is responsible for retrieving either cached credentials /// or forcing a prompt if we need the user to give us new credentials. /// </summary> private ICredentials PromptForCredentials(Uri uri) { const __VsWebProxyState oldState = __VsWebProxyState.VsWebProxyState_PromptForCredentials; var newState = (uint)__VsWebProxyState.VsWebProxyState_NoCredentials; int result = 0; ThreadHelper.Generic.Invoke(() => { result = _webProxyService.PrepareWebProxy(uri.OriginalString, (uint)oldState, out newState, fOkToPrompt: 1); }); // If result is anything but 0 that most likely means that there was an error // so we will null out the DefaultWebProxy.Credentials so that we don't get // invalid credentials stored for subsequent requests. if (result != 0 || newState == (uint)__VsWebProxyState.VsWebProxyState_Abort) { // Clear out the current credentials because the user might have clicked cancel // and we don't want to use the currently set credentials if they are wrong. return(null); } // Get the new credentials from the proxy instance return(WebRequest.DefaultWebProxy.Credentials); }
/// <summary> /// This method is responsible for retrieving either cached credentials /// or forcing a prompt if we need the user to give us new credentials. /// </summary> private Task <ICredentials> PromptForCredentials(Uri uri, CancellationToken cancellationToken) { const __VsWebProxyState oldState = __VsWebProxyState.VsWebProxyState_PromptForCredentials; var newState = (uint)__VsWebProxyState.VsWebProxyState_NoCredentials; int result = 0; cancellationToken.ThrowIfCancellationRequested(); ThreadHelper.JoinableTaskFactory.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); result = _webProxyService.PrepareWebProxy(uri.OriginalString, (uint)oldState, out newState, fOkToPrompt: 1); }); // If result is anything but 0 that most likely means that there was an error // so we will null out the DefaultWebProxy.Credentials so that we don't get // invalid credentials stored for subsequent requests. if (result != 0 || newState == (uint)__VsWebProxyState.VsWebProxyState_Abort) { // Clear out the current credentials because the user might have clicked cancel // and we don't want to use the currently set credentials if they are wrong. throw new OperationCanceledException(); } // Get the new credentials from the proxy instance return(System.Threading.Tasks.Task.FromResult(WebRequest.DefaultWebProxy.Credentials)); }
public async Task <bool> TryUpdateCredentialsAsync(Uri uri, IWebProxy proxy, CredentialRequestType type, CancellationToken cancellationToken) { // This value will cause the web proxy service to first attempt to retrieve // credentials from its cache and fall back to prompting if necessary. const __VsWebProxyState oldState = __VsWebProxyState.VsWebProxyState_DefaultCredentials; // This must be run on the UI thread in case a prompt has to be shown to retrieve the credentials await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var result = _vsWebProxy.PrepareWebProxy(uri.OriginalString, (uint)oldState, out var newState, fOkToPrompt: 1); return(result == 0 && newState != (uint)__VsWebProxyState.VsWebProxyState_Abort); }