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
8#include <string>
9
10#include "base/strings/string16.h"
11#include "net/base/net_export.h"
12#include "url/origin.h"
13
14namespace net {
15
16// Holds info about an authentication challenge that we may want to display
17// to the user.
18class NET_EXPORT AuthChallengeInfo {
19 public:
20 AuthChallengeInfo();
21 AuthChallengeInfo(const AuthChallengeInfo& other);
22 ~AuthChallengeInfo();
23
24 bool operator==(const AuthChallengeInfo& other) const;
25 bool operator!=(const AuthChallengeInfo& other) const;
26
27 // Whether this came from a server or a proxy.
28 bool is_proxy;
29
30 // The service issuing the challenge.
31 url::Origin challenger;
32
33 // The authentication scheme used, such as "basic" or "digest". If the
34 // |source| is FTP_SERVER, this is an empty string. The encoding is ASCII.
35 std::string scheme;
36
37 // The realm of the challenge. May be empty. The encoding is UTF-8.
38 std::string realm;
39};
40
41// Authentication Credentials for an authentication credentials.
42class NET_EXPORT AuthCredentials {
43 public:
44 AuthCredentials();
45 AuthCredentials(const base::string16& username,
46 const base::string16& password);
47 ~AuthCredentials();
48
49 // Set the |username| and |password|.
50 void Set(const base::string16& username, const base::string16& password);
51
52 // Determines if |this| is equivalent to |other|.
53 bool Equals(const AuthCredentials& other) const;
54
55 // Returns true if all credentials are empty.
56 bool Empty() const;
57
58 const base::string16& username() const { return username_; }
59 const base::string16& password() const { return password_; }
60
61 private:
62 // The username to provide, possibly empty. This should be ASCII only to
63 // minimize compatibility problems, but arbitrary UTF-16 strings are allowed
64 // and will be attempted.
65 base::string16 username_;
66
67 // The password to provide, possibly empty. This should be ASCII only to
68 // minimize compatibility problems, but arbitrary UTF-16 strings are allowed
69 // and will be attempted.
70 base::string16 password_;
71
72 // Intentionally allowing the implicit copy constructor and assignment
73 // operators.
74};
75
76// Authentication structures
77enum AuthState {
78 AUTH_STATE_DONT_NEED_AUTH,
79 AUTH_STATE_NEED_AUTH,
80 AUTH_STATE_HAVE_AUTH,
81 AUTH_STATE_CANCELED
82};
83
84} // namespace net
85
86#endif // NET_BASE_AUTH_H__
87