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