Credentials.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. namespace BestHTTP.Authentication
  2. {
  3. /// <summary>
  4. /// Authentication types that supported by BestHTTP.
  5. /// The authentication is defined by the server, so the Basic and Digest are not interchangeable. If you don't know what to use, the preferred way is to choose Unknow.
  6. /// </summary>
  7. public enum AuthenticationTypes
  8. {
  9. /// <summary>
  10. /// If the authentication type is not known this will do a challenge turn to receive what methode should be choosen.
  11. /// </summary>
  12. Unknown,
  13. /// <summary>
  14. /// The most basic authentication type. It's easy to do, and easy to crack. ;)
  15. /// </summary>
  16. Basic,
  17. /// <summary>
  18. ///
  19. /// </summary>
  20. Digest
  21. }
  22. /// <summary>
  23. /// Hold all information that required to authenticate to a remote server.
  24. /// </summary>
  25. public sealed class Credentials
  26. {
  27. /// <summary>
  28. /// The type of the Authentication. If you don't know what to use, the preferred way is to choose Unknow.
  29. /// </summary>
  30. public AuthenticationTypes Type { get; private set; }
  31. /// <summary>
  32. /// The username to authenticate on the remote server.
  33. /// </summary>
  34. public string UserName { get; private set; }
  35. /// <summary>
  36. /// The password to use in the authentication process. The password will be stored only in this class.
  37. /// </summary>
  38. public string Password { get; private set; }
  39. /// <summary>
  40. /// Set up the authentication credentials with the username and password. The Type will be set to Unknown.
  41. /// </summary>
  42. public Credentials(string userName, string password)
  43. :this(AuthenticationTypes.Unknown, userName, password)
  44. {
  45. }
  46. /// <summary>
  47. /// Set up the authentication credentials with the given authentication type, username and password.
  48. /// </summary>
  49. public Credentials(AuthenticationTypes type, string userName, string password)
  50. {
  51. this.Type = type;
  52. this.UserName = userName;
  53. this.Password = password;
  54. }
  55. }
  56. }