/// <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]); } }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
/// <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) { }
/// <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) { }
/// <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) { }