コード例 #1
0
ファイル: ConnectionInfo.cs プロジェクト: zjrunner/prism
        public async Task <ClientConnectionInfo> GetConnection()
        {
            if (_connection == null)
            {
                _connection = await ClientConnectionInfo.Resolve(
                    _contextAccessor.HttpContext.Connection.RemotePort,
                    _contextAccessor.HttpContext.Connection.LocalPort);
            }

            return(_connection);
        }
コード例 #2
0
ファイル: AuthProvider.cs プロジェクト: zjrunner/prism
        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
ファイル: AuthProvider.cs プロジェクト: zjrunner/prism
        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;
 }