예제 #1
0
        public async Task <ClientConnectionInfo> GetConnection()
        {
            if (_connection == null)
            {
                _connection = await ClientConnectionInfo.Resolve(
                    _contextAccessor.HttpContext.Connection.RemotePort,
                    _contextAccessor.HttpContext.Connection.LocalPort);
            }

            return(_connection);
        }
예제 #2
0
        public AuthenticationHeaderValue GetAuthenticationHeader(Uri destination, ClientConnectionInfo connection, bool retry)
        {
            if (!CanAuthenticate(destination, connection))
            {
                throw new InvalidOperationException("Authentication is not allowed for this connection.");
            }

            string exceptionString = null;

            if (retry || string.IsNullOrEmpty(_bearerToken))
            {
                lock (_lockKey)
                {
                    if (retry || string.IsNullOrEmpty(_bearerToken))
                    {
                        Environment.SetEnvironmentVariable("NUGET_CREDENTIALPROVIDER_VSTS_TOKENTYPE", "SelfDescribing");
                        Environment.SetEnvironmentVariable("NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED", "true");

                        string retryArg  = retry ? "-I" : null;
                        var    procStart = new ProcessStartInfo(_credProviderPath, $"-C -V Information {retryArg} -U {destination}")
                        {
                            RedirectStandardOutput = true,
                            RedirectStandardError  = true
                        };
                        var proc = Process.Start(procStart);
                        proc.WaitForExit();

                        string line;
                        while ((line = proc.StandardOutput.ReadLine()) != null)
                        {
                            int index;
                            if ((index = line.IndexOf("Password:"******"Password:"******"{proc.ExitCode} : {proc.StandardError.ReadToEnd()}";
                    }
                }

                if (string.IsNullOrEmpty(_bearerToken))
                {
                    throw new AuthorizationException($"Couldn't validate to {destination} - auth failure: {exceptionString}");
                }
            }

            return(new AuthenticationHeaderValue("Bearer", _bearerToken));
        }
예제 #3
0
        public bool CanAuthenticate(Uri destination, ClientConnectionInfo connection)
        {
            if (!connection.IsRemoteUserSameAsCurrent)
            {
                return(false);
            }

            if (!destination.Host.EndsWith(".visualstudio.com", StringComparison.OrdinalIgnoreCase) &&
                !destination.Host.EndsWith("dev.azure.com", StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }


            return(true);
        }
예제 #4
0
 public TrackedRequest(HttpRequest request, UriForwardingTransformer uriTransformer, ClientConnectionInfo connection)
     : base(request.Headers)
 {
     Order       = Interlocked.Increment(ref _globalOrder);
     Id          = Guid.NewGuid();
     OriginalUri = new Uri(Microsoft.AspNetCore.Http.Extensions.UriHelper.GetEncodedUrl(request));
     Uri         = uriTransformer.GetUriForActualHost(request.Path, request.QueryString.Value);
     Method      = request.Method;
     Session     = connection.Session;
 }