public AuthenticationResponse(WsCredential credential, AuthenticationChallenge challenge)
 {
     _userName = credential.UserName;
       _password = credential.Password;
       _scheme = challenge.Scheme;
       _realm = challenge.Realm;
       if (_scheme == "Digest")
     initForDigest(credential, challenge);
 }
 public AuthenticationResponse(WsCredential credential, AuthenticationChallenge challenge)
 {
     _userName = credential.UserName;
     _password = credential.Password;
     _scheme   = challenge.Scheme;
     _realm    = challenge.Realm;
     if (_scheme == "Digest")
     {
         initForDigest(credential, challenge);
     }
 }
        private void initForDigest(WsCredential credential, AuthenticationChallenge challenge)
        {
            _nonce     = challenge.Nonce;
            _method    = "GET";
            _uri       = credential.Domain;
            _algorithm = challenge.Algorithm;
            _opaque    = challenge.Opaque;
            foreach (var qop in challenge.Qop.Split(','))
            {
                if (qop.Trim().ToLower() == "auth")
                {
                    _qop = "auth";
                    _nc  = "00000001";
                    break;
                }
            }

            _cnonce   = createNonceValue();
            _response = createRequestDigest();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the credentials for HTTP authentication (Basic/Digest).
        /// </summary>
        /// <param name="userName">
        /// A <see cref="string"/> that contains a user name associated with the credentials.
        /// </param>
        /// <param name="password">
        /// A <see cref="string"/> that contains a password for <paramref name="userName"/> associated with the credentials.
        /// </param>
        /// <param name="preAuth">
        /// <c>true</c> if sends the credentials as a Basic authorization with the first request handshake;
        /// otherwise, <c>false</c>.
        /// </param>
        public void SetCredentials(string userName, string password, bool preAuth)
        {
            string msg = null;
              if (IsOpened)
              {
            msg = "A WebSocket connection has already been established.";
              }
              else if (userName == null)
              {
            _credentials = null;
            _preAuth = false;

            return;
              }
              else
              {
            msg = userName.Length > 0 && (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 (msg);

            return;
              }

              _credentials = new WsCredential (userName, password, _uri.PathAndQuery);
              _preAuth = preAuth;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Sets the credentials for HTTP authentication (Basic/Digest).
        /// </summary>
        /// <param name="userName">
        /// A <see cref="string"/> that contains a user name associated with the credentials.
        /// </param>
        /// <param name="password">
        /// A <see cref="string"/> that contains a password for <paramref name="userName"/> associated with the credentials.
        /// </param>
        /// <param name="preAuth">
        /// <c>true</c> if sends the credentials as a Basic authorization with the first request handshake;
        /// otherwise, <c>false</c>.
        /// </param>
        public void SetCredentials(string userName, string password, bool preAuth)
        {
            if (isOpened(true))
            return;

              if (userName == null)
              {
            _credentials = null;
            _preAuth = false;

            return;
              }

              var error = userName.Length > 0 && (userName.Contains(':') || !userName.IsText())
                ? "'userName' contains an invalid character."
                : !password.IsNullOrEmpty() && !password.IsText()
                  ? "'password' contains an invalid character."
                  : String.Empty;

              if (error.Length > 0)
              {
            onError(error);
            return;
              }

              _credentials = new WsCredential(userName, password, _uri.PathAndQuery);
              _preAuth = preAuth;
        }
 public AuthenticationResponse(WsCredential credential)
 {
     _userName = credential.UserName;
     _password = credential.Password;
     _scheme   = "Basic";
 }
 public AuthenticationResponse(WsCredential credential)
 {
     _userName = credential.UserName;
       _password = credential.Password;
       _scheme = "Basic";
 }
        private void initForDigest(WsCredential credential, AuthenticationChallenge challenge)
        {
            _nonce = challenge.Nonce;
              _method = "GET";
              _uri = credential.Domain;
              _algorithm = challenge.Algorithm;
              _opaque = challenge.Opaque;
              foreach (var qop in challenge.Qop.Split(','))
              {
            if (qop.Trim().ToLower() == "auth")
            {
              _qop = "auth";
              _nc = "00000001";
              break;
            }
              }

              _cnonce = createNonceValue();
              _response = createRequestDigest();
        }