• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #ifndef NET_BASE_AUTH_H__
6 #define NET_BASE_AUTH_H__
7 #pragma once
8 
9 #include <string>
10 
11 #include "base/memory/ref_counted.h"
12 #include "base/string16.h"
13 
14 namespace net {
15 
16 // Holds info about an authentication challenge that we may want to display
17 // to the user.
18 class AuthChallengeInfo :
19     public base::RefCountedThreadSafe<AuthChallengeInfo> {
20  public:
21   AuthChallengeInfo();
22 
23   bool operator==(const AuthChallengeInfo& that) const;
24 
25   bool operator!=(const AuthChallengeInfo& that) const {
26     return !(*this == that);
27   }
28 
29   bool is_proxy;  // true for Proxy-Authenticate, false for WWW-Authenticate.
30   std::wstring host_and_port;  // <host>:<port> of the server asking for auth
31                                // (could be the proxy).
32   std::wstring scheme;  // "Basic", "Digest", or whatever other method is used.
33   std::wstring realm;  // the realm provided by the server, if there is one.
34 
35  private:
36   friend class base::RefCountedThreadSafe<AuthChallengeInfo>;
37   ~AuthChallengeInfo();
38 };
39 
40 // Authentication structures
41 enum AuthState {
42   AUTH_STATE_DONT_NEED_AUTH,
43   AUTH_STATE_NEED_AUTH,
44   AUTH_STATE_HAVE_AUTH,
45   AUTH_STATE_CANCELED
46 };
47 
48 class AuthData : public base::RefCountedThreadSafe<AuthData> {
49  public:
50   AuthState state;  // whether we need, have, or gave up on authentication.
51   std::wstring scheme;  // the authentication scheme.
52   string16 username;  // the username supplied to us for auth.
53   string16 password;  // the password supplied to us for auth.
54 
55   // We wouldn't instantiate this class if we didn't need authentication.
56   AuthData();
57 
58  private:
59   friend class base::RefCountedThreadSafe<AuthData>;
60   ~AuthData();
61 };
62 
63 }  // namespace net
64 
65 #endif  // NET_BASE_AUTH_H__
66