A HTTP basic authentication.
예제 #1
0
        /// <summary>
        /// Try to parse the given text.
        /// </summary>
        /// <param name="Text">A text representation of a HTTP basic authentication header.</param>
        /// <param name="BasicAuthentication">The parsed HTTP basic authentication header.</param>
        /// <returns>true, when the parsing was successful, else false.</returns>
        public static Boolean TryParse(String Text, out HTTPBasicAuthentication BasicAuthentication)
        {
            BasicAuthentication = null;

            if (Text.IsNullOrEmpty())
            {
                return(false);
            }

            var splitted = Text.Split(new Char[] { ' ' });

            if (splitted.IsNullOrEmpty())
            {
                return(false);
            }

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

                if (usernamePassword.IsNullOrEmpty())
                {
                    return(false);
                }

                BasicAuthentication = new HTTPBasicAuthentication(usernamePassword[0], usernamePassword[1]);
                return(true);
            }

            return(false);
        }
예제 #2
0
 /// <summary>
 /// Set the HTTP Authorization header field.
 /// </summary>
 /// <param name="Authorization">Authorization.</param>
 public HTTPRequestBuilder SetAuthorization(HTTPBasicAuthentication Authorization)
 {
     this.Authorization = Authorization;
     return(this);
 }
예제 #3
0
        /// <summary>
        /// Try to parse the given text.
        /// </summary>
        /// <param name="Text">A text representation of a HTTP basic authentication header.</param>
        /// <param name="BasicAuthentication">The parsed HTTP basic authentication header.</param>
        /// <returns>true, when the parsing was successful, else false.</returns>
        public static Boolean TryParse(String Text, out HTTPBasicAuthentication BasicAuthentication)
        {
            BasicAuthentication = null;

            if (Text.IsNullOrEmpty())
                return false;

            var splitted = Text.Split(new Char[] { ' ' });

            if (splitted.IsNullOrEmpty())
                return false;

            if (splitted[0].ToLower() == "basic")
            {

                var usernamePassword = splitted[1].FromBase64().Split(new Char[] { ':' });

                if (usernamePassword.IsNullOrEmpty())
                    return false;

                BasicAuthentication = new HTTPBasicAuthentication(usernamePassword[0], usernamePassword[1]);
                return true;

            }

            return false;
        }
예제 #4
0
 /// <summary>
 /// Set the HTTP Authorization header field.
 /// </summary>
 /// <param name="Authorization">Authorization.</param>
 public HTTPRequestBuilder SetAuthorization(HTTPBasicAuthentication Authorization)
 {
     this.Authorization = Authorization;
     return this;
 }