コード例 #1
0
ファイル: HTTPCredentials.cs プロジェクト: zhouweiaccp/sones
        /// <summary>
        /// Create the credentials based on a base64 encoded string which comes from a HTTP header Authentication:
        /// </summary>
        /// <param name="myHTTPHeaderCredential"></param>
        public HTTPCredentials(String myHTTPHeaderCredential)
        {
            var splitted = myHTTPHeaderCredential.Split(new[] { ' ' });

            if (splitted.IsNullOrEmpty())
            {
                throw new ArgumentException("invalid credentials " + myHTTPHeaderCredential);
            }

            if (splitted[0].ToLower() == "basic")
            {
                HTTPCredentialType = HTTPAuthenticationTypes.Basic;
                var usernamePassword = splitted[1].FromBase64().Split(new[] { ':' });

                if (usernamePassword.IsNullOrEmpty())
                {
                    throw new ArgumentException("invalid username/password " + splitted[1].FromBase64());
                }

                Username = usernamePassword[0];
                Password = usernamePassword[1];
            }
            else
            {
                throw new ArgumentException("invalid credentialType " + splitted[0]);
            }
        }
コード例 #2
0
        /// <summary>
        /// Create the credentials based on a base64 encoded string which comes from a HTTP header Authentication:
        /// </summary>
        /// <param name="Username">The username.</param>
        /// <param name="Password">The password.</param>
        public HTTPBasicAuthentication(String  Username,
                                       String  Password)
        {
            #region Initial checks

            if (Username.IsNullOrEmpty())
                throw new ArgumentNullException(nameof(Username), "The given username must not be null or empty!");

            if (Password.IsNullOrEmpty())
                throw new ArgumentNullException(nameof(Password), "The given password must not be null or empty!");

            #endregion

            this._HTTPCredentialType  = HTTPAuthenticationTypes.Basic;
            this._Username            = Username;
            this._Password            = Password;
        }
コード例 #3
0
        /// <summary>
        /// Create the credentials based on a base64 encoded string which comes from a HTTP header Authentication:
        /// </summary>
        /// <param name="Username">The username.</param>
        /// <param name="Password">The password.</param>
        public HTTPBasicAuthentication(String Username,
                                       String Password)
        {
            #region Initial checks

            if (Username.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Username), "The given username must not be null or empty!");
            }

            if (Password.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Password), "The given password must not be null or empty!");
            }

            #endregion

            this._HTTPCredentialType = HTTPAuthenticationTypes.Basic;
            this._Username           = Username;
            this._Password           = Password;
        }
コード例 #4
0
 /// <summary>
 /// The generic HTTP authentication attribute including a realm.
 /// </summary>
 /// <param name="AuthenticationType">The authentication type(s).</param>
 /// <param name="Realm">The HTTP realm.</param>
 internal AuthenticationAttribute(HTTPAuthenticationTypes AuthenticationType, String Realm)
 {
     this.AuthenticationType = AuthenticationType;
     this.Realm = Realm;
 }
コード例 #5
0
 /// <summary>
 /// The generic HTTP authentication attribute.
 /// </summary>
 /// <param name="AuthenticationType">The authentication type(s).</param>
 internal AuthenticationAttribute(HTTPAuthenticationTypes AuthenticationType)
 {
     this.AuthenticationType = AuthenticationType;
     this.Realm              = String.Empty;
 }
コード例 #6
0
 /// <summary>
 /// Optional authentication possible.
 /// </summary>
 /// <param name="AuthenticationType">The authentication type(s).</param>
 /// <param name="Realm">The HTTP realm.</param>
 public OptionalAuthenticationAttribute(HTTPAuthenticationTypes AuthenticationType, String Realm)
     : base(AuthenticationType, Realm)
 {
 }
コード例 #7
0
 /// <summary>
 /// Optional authentication possible.
 /// </summary>
 /// <param name="AuthenticationType">The authentication type(s).</param>
 /// <param name="Realm">The HTTP realm.</param>
 public OptionalAuthenticationAttribute(HTTPAuthenticationTypes AuthenticationType)
     : base(AuthenticationType)
 {
 }
コード例 #8
0
 /// <summary>
 /// The generic HTTP authentication attribute including a realm.
 /// </summary>
 /// <param name="AuthenticationType">The authentication type(s).</param>
 /// <param name="Realm">The HTTP realm.</param>
 internal AuthenticationAttribute(HTTPAuthenticationTypes AuthenticationType, String Realm)
 {
     this.AuthenticationType = AuthenticationType;
     this.Realm = Realm;
 }
コード例 #9
0
 /// <summary>
 /// The generic HTTP authentication attribute.
 /// </summary>
 /// <param name="AuthenticationType">The authentication type(s).</param>
 internal AuthenticationAttribute(HTTPAuthenticationTypes AuthenticationType)
 {
     this.AuthenticationType = AuthenticationType;
     this.Realm = String.Empty;
 }
コード例 #10
0
 /// <summary>
 /// HTTP authentication required.
 /// </summary>
 /// <param name="AuthenticationType">The authentication type(s).</param>
 /// <param name="Realm">The HTTP realm.</param>
 public ForceAuthenticationAttribute(HTTPAuthenticationTypes AuthenticationType, String Realm)
     : base(AuthenticationType, Realm)
 {
 }
コード例 #11
0
 /// <summary>
 /// Optional authentication possible.
 /// </summary>
 /// <param name="AuthenticationType">The authentication type(s).</param>
 /// <param name="Realm">The HTTP realm.</param>
 public OptionalAuthenticationAttribute(HTTPAuthenticationTypes AuthenticationType)
     : base(AuthenticationType)
 {
 }