auth.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef NET_BASE_AUTH_H__
  5. #define NET_BASE_AUTH_H__
  6. #include <string>
  7. #include "net/base/net_export.h"
  8. #include "url/scheme_host_port.h"
  9. namespace net {
  10. // Holds info about an authentication challenge that we may want to display
  11. // to the user.
  12. class NET_EXPORT AuthChallengeInfo {
  13. public:
  14. AuthChallengeInfo();
  15. AuthChallengeInfo(const AuthChallengeInfo& other);
  16. ~AuthChallengeInfo();
  17. // Returns true if this AuthChallengeInfo is equal to |other| except for
  18. // |path|. Can be used to determine if the same credentials can be provided
  19. // for two different requests.
  20. bool MatchesExceptPath(const AuthChallengeInfo& other) const;
  21. // Whether this came from a server or a proxy.
  22. bool is_proxy = false;
  23. // The service issuing the challenge.
  24. url::SchemeHostPort challenger;
  25. // The authentication scheme used, such as "basic" or "digest". The encoding
  26. // is ASCII.
  27. std::string scheme;
  28. // The realm of the challenge. May be empty. The encoding is UTF-8.
  29. std::string realm;
  30. // The authentication challenge.
  31. std::string challenge;
  32. // The path on which authentication was requested.
  33. std::string path;
  34. };
  35. // Authentication Credentials for an authentication credentials.
  36. class NET_EXPORT AuthCredentials {
  37. public:
  38. AuthCredentials();
  39. AuthCredentials(const std::u16string& username,
  40. const std::u16string& password);
  41. ~AuthCredentials();
  42. // Set the |username| and |password|.
  43. void Set(const std::u16string& username, const std::u16string& password);
  44. // Determines if |this| is equivalent to |other|.
  45. bool Equals(const AuthCredentials& other) const;
  46. // Returns true if all credentials are empty.
  47. bool Empty() const;
  48. const std::u16string& username() const { return username_; }
  49. const std::u16string& password() const { return password_; }
  50. private:
  51. // The username to provide, possibly empty. This should be ASCII only to
  52. // minimize compatibility problems, but arbitrary UTF-16 strings are allowed
  53. // and will be attempted.
  54. std::u16string username_;
  55. // The password to provide, possibly empty. This should be ASCII only to
  56. // minimize compatibility problems, but arbitrary UTF-16 strings are allowed
  57. // and will be attempted.
  58. std::u16string password_;
  59. // Intentionally allowing the implicit copy constructor and assignment
  60. // operators.
  61. };
  62. // Authentication structures
  63. enum AuthState {
  64. AUTH_STATE_DONT_NEED_AUTH,
  65. AUTH_STATE_NEED_AUTH,
  66. AUTH_STATE_HAVE_AUTH,
  67. AUTH_STATE_CANCELED
  68. };
  69. } // namespace net
  70. #endif // NET_BASE_AUTH_H__