Ejemplo n.º 1
0
 internal AuthenticationResponse (
   AuthenticationSchemes scheme,
   NameValueCollection parameters,
   NetworkCredential credentials,
   uint nonceCount)
   : base (scheme, parameters)
 {
   Parameters["username"] = credentials.UserName;
   Parameters["password"] = credentials.Password;
   Parameters["uri"] = credentials.Domain;
   _nonceCount = nonceCount;
   if (scheme == AuthenticationSchemes.Digest)
     initAsDigest ();
 }
Ejemplo n.º 2
0
    /// <summary>
    /// Sets an HTTP Proxy server URL to connect through, and if necessary, a pair of
    /// <paramref name="username"/> and <paramref name="password"/> for the proxy server
    /// authentication (Basic/Digest).
    /// </summary>
    /// <param name="url">
    /// A <see cref="string"/> that represents the proxy server URL to connect through.
    /// </param>
    /// <param name="username">
    /// A <see cref="string"/> that represents the user name used to authenticate.
    /// </param>
    /// <param name="password">
    /// A <see cref="string"/> that represents the password for <paramref name="username"/>
    /// used to authenticate.
    /// </param>
    public void SetProxy (string url, string username, string password)
    {
      lock (_forConn) {
        var msg = checkIfAvailable (false, false);
        if (msg == null) {
          if (url.IsNullOrEmpty ()) {
            _proxyUri = null;
            _proxyCredentials = null;
            _logger.Warn ("The proxy url and credentials were set back to the default.");

            return;
          }

          Uri uri;
          if (!Uri.TryCreate (url, UriKind.Absolute, out uri) ||
              uri.Scheme != "http" ||
              uri.Segments.Length > 1) {
            msg = "The syntax of the proxy url must be 'http://<host>[:<port>]'.";
          }
          else {
            _proxyUri = uri;

            if (username.IsNullOrEmpty ()) {
              _proxyCredentials = null;
              _logger.Warn ("The proxy credentials were set back to the default.");

              return;
            }

            msg = username.Contains (':') || !username.IsText ()
                  ? "'username' contains an invalid character."
                  : !password.IsNullOrEmpty () && !password.IsText ()
                    ? "'password' contains an invalid character."
                    : null;
          }
        }

        if (msg != null) {
          _logger.Error (msg);
          error ("An error has occurred in setting the proxy.", null);

          return;
        }

        _proxyCredentials = new NetworkCredential (
          username, password, String.Format ("{0}:{1}", _uri.DnsSafeHost, _uri.Port));
      }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Sets a pair of <paramref name="username"/> and <paramref name="password"/> for
    /// the HTTP authentication (Basic/Digest).
    /// </summary>
    /// <param name="username">
    /// A <see cref="string"/> that represents the user name used to authenticate.
    /// </param>
    /// <param name="password">
    /// A <see cref="string"/> that represents the password for <paramref name="username"/>
    /// used to authenticate.
    /// </param>
    /// <param name="preAuth">
    /// <c>true</c> if the <see cref="WebSocket"/> sends the Basic authentication credentials
    /// with the first connection request to the server; otherwise, <c>false</c>.
    /// </param>
    public void SetCredentials (string username, string password, bool preAuth)
    {
      lock (_forConn) {
        var msg = checkIfAvailable (false, false);
        if (msg == null) {
          if (username.IsNullOrEmpty ()) {
            _credentials = null;
            _preAuth = false;
            _logger.Warn ("The credentials were set back to the default.");

            return;
          }

          msg = username.Contains (':') || !username.IsText ()
                ? "'username' contains an invalid character."
                : !password.IsNullOrEmpty () && !password.IsText ()
                  ? "'password' contains an invalid character."
                  : null;
        }

        if (msg != null) {
          _logger.Error (msg);
          error ("An error has occurred in setting the credentials.", null);

          return;
        }

        _credentials = new NetworkCredential (username, password, _uri.PathAndQuery);
        _preAuth = preAuth;
      }
    }
Ejemplo n.º 4
0
 internal AuthenticationResponse (
   AuthenticationChallenge challenge, NetworkCredential credentials, uint nonceCount)
   : this (challenge.Scheme, challenge.Parameters, credentials, nonceCount)
 {
 }
Ejemplo n.º 5
0
 internal AuthenticationResponse (NetworkCredential credentials)
   : this (AuthenticationSchemes.Basic, new NameValueCollection (), credentials, 0)
 {
 }