Exemplo n.º 1
0
        private async Task <ICredentials> PromptForCredentialsAsync(
            CredentialRequestType type,
            string message,
            AmbientAuthenticationState authState,
            ILogger log,
            CancellationToken token)
        {
            ICredentials promptCredentials;

            // Only one prompt may display at a time.
            await _credentialPromptLock.WaitAsync();

            try
            {
                // Get the proxy for this URI so we can pass it to the credentialService methods
                // this lets them use the proxy if they have to hit the network.
                var proxyCache = ProxyCache.Instance;
                var proxy      = proxyCache?.GetProxy(_packageSource.SourceUri);

                promptCredentials = await _credentialService
                                    .GetCredentialsAsync(_packageSource.SourceUri, proxy, type, message, token);

                if (promptCredentials == null)
                {
                    // If this is the case, this means none of the credential providers were able to
                    // handle the credential request or no credentials were available for the
                    // endpoint.
                    authState.Block();
                }
                else
                {
                    authState.Increment();
                }
            }
            catch (OperationCanceledException)
            {
                // This indicates a non-human cancellation.
                throw;
            }
            catch (Exception e)
            {
                // If this is the case, this means there was a fatal exception when interacting
                // with the credential service (or its underlying credential providers). Either way,
                // block asking for credentials for the live of this operation.
                log.LogError(ExceptionUtilities.DisplayMessage(e));
                promptCredentials = null;
                authState.Block();
            }
            finally
            {
                _credentialPromptLock.Release();
            }

            return(promptCredentials);
        }
Exemplo n.º 2
0
        private AmbientAuthenticationState GetAuthenticationState()
        {
            var correlationId = ActivityCorrelationId.Current;

            AmbientAuthenticationState authState;

            if (!_authStates.TryGetValue(correlationId, out authState))
            {
                authState = new AmbientAuthenticationState();
                _authStates[correlationId] = authState;
            }

            return(authState);
        }
Exemplo n.º 3
0
        private AmbientAuthenticationState GetAuthenticationState()
        {
            var correlationId = ActivityCorrelationContext.Current.CorrelationId;

            AmbientAuthenticationState authState;

            if (!_authStates.TryGetValue(correlationId, out authState))
            {
                authState = new AmbientAuthenticationState
                {
                    IsBlocked = false,
                    AuthenticationRetriesCount = 0
                };
                _authStates[correlationId] = authState;
            }

            return(authState);
        }