Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: chrome/common/net/gaia/google_service_auth_error.h

Issue 10928017: Moving google_apis and GaiaClient to src/google_apis. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 // A GoogleServiceAuthError is immutable, plain old data representing an
6 // error from an attempt to authenticate with a Google service.
7 // It could be from Google Accounts itself, or any service using Google
8 // Accounts (e.g expired credentials). It may contain additional data such as
9 // captcha or OTP challenges.
10
11 // A GoogleServiceAuthError without additional data is just a State, defined
12 // below. A case could be made to have this relation implicit, to allow raising
13 // error events concisely by doing OnAuthError(GoogleServiceAuthError::NONE),
14 // for example. But the truth is this class is ever so slightly more than a
15 // transparent wrapper around 'State' due to additional Captcha data
16 // (e.g consider operator=), and this would violate the style guide. Thus,
17 // you must explicitly use the constructor when all you have is a State.
18 // The good news is the implementation nests the enum inside a class, so you
19 // may forward declare and typedef GoogleServiceAuthError to something shorter
20 // in the comfort of your own translation unit.
21
22 #ifndef CHROME_COMMON_NET_GAIA_GOOGLE_SERVICE_AUTH_ERROR_H_
23 #define CHROME_COMMON_NET_GAIA_GOOGLE_SERVICE_AUTH_ERROR_H_
24
25 #include <string>
26
27 #include "googleurl/src/gurl.h"
28
29 namespace base {
30 class DictionaryValue;
31 }
32
33 class GoogleServiceAuthError {
34 public:
35 //
36 // These enumerations are referenced by integer value in HTML login code.
37 // Do not change the numeric values.
38 //
39 enum State {
40 // The user is authenticated.
41 NONE = 0,
42
43 // The credentials supplied to GAIA were either invalid, or the locally
44 // cached credentials have expired.
45 INVALID_GAIA_CREDENTIALS = 1,
46
47 // The GAIA user is not authorized to use the service.
48 USER_NOT_SIGNED_UP = 2,
49
50 // Could not connect to server to verify credentials. This could be in
51 // response to either failure to connect to GAIA or failure to connect to
52 // the service needing GAIA tokens during authentication.
53 CONNECTION_FAILED = 3,
54
55 // The user needs to satisfy a CAPTCHA challenge to unlock their account.
56 // If no other information is available, this can be resolved by visiting
57 // https://accounts.google.com/DisplayUnlockCaptcha. Otherwise, captcha()
58 // will provide details about the associated challenge.
59 CAPTCHA_REQUIRED = 4,
60
61 // The user account has been deleted.
62 ACCOUNT_DELETED = 5,
63
64 // The user account has been disabled.
65 ACCOUNT_DISABLED = 6,
66
67 // The service is not available; try again later.
68 SERVICE_UNAVAILABLE = 7,
69
70 // The password is valid but we need two factor to get a token.
71 TWO_FACTOR = 8,
72
73 // The requestor of the authentication step cancelled the request
74 // prior to completion.
75 REQUEST_CANCELED = 9,
76
77 // The user has provided a HOSTED account, when this service requires
78 // a GOOGLE account.
79 HOSTED_NOT_ALLOWED = 10,
80 };
81
82 // Additional data for CAPTCHA_REQUIRED errors.
83 struct Captcha {
84 Captcha();
85 Captcha(const std::string& token,
86 const GURL& audio,
87 const GURL& img,
88 const GURL& unlock,
89 int width,
90 int height);
91 ~Captcha();
92 // For test only.
93 bool operator==(const Captcha &b) const;
94
95 std::string token; // Globally identifies the specific CAPTCHA challenge.
96 GURL audio_url; // The CAPTCHA audio to use instead of image.
97 GURL image_url; // The CAPTCHA image to show the user.
98 GURL unlock_url; // Pretty unlock page containing above captcha.
99 int image_width; // Width of captcha image.
100 int image_height; // Height of capture image.
101 };
102
103 // Additional data for TWO_FACTOR errors.
104 struct SecondFactor {
105 SecondFactor();
106 SecondFactor(const std::string& token,
107 const std::string& prompt,
108 const std::string& alternate,
109 int length);
110 ~SecondFactor();
111 // For test only.
112 bool operator==(const SecondFactor &b) const;
113
114 // Globally identifies the specific second-factor challenge.
115 std::string token;
116 // Localised prompt text, eg “Enter the verification code sent to your
117 // phone number ending in XXX”.
118 std::string prompt_text;
119 // Localized text describing an alternate option, eg “Get a verification
120 // code in a text message”.
121 std::string alternate_text;
122 // Character length for the challenge field.
123 int field_length;
124 };
125
126 // For test only.
127 bool operator==(const GoogleServiceAuthError &b) const;
128
129 // Construct a GoogleServiceAuthError from a State with no additional data.
130 explicit GoogleServiceAuthError(State s);
131
132 // Construct a GoogleServiceAuthError from a network error.
133 // It will be created with CONNECTION_FAILED set.
134 static GoogleServiceAuthError FromConnectionError(int error);
135
136 // Construct a CAPTCHA_REQUIRED error with CAPTCHA challenge data from the
137 // the ClientLogin endpoint.
138 // TODO(rogerta): once ClientLogin is no longer used, may be able to get
139 // rid of this function.
140 static GoogleServiceAuthError FromClientLoginCaptchaChallenge(
141 const std::string& captcha_token,
142 const GURL& captcha_image_url,
143 const GURL& captcha_unlock_url);
144
145 // Construct a CAPTCHA_REQUIRED error with CAPTCHA challenge data from the
146 // ClientOAuth endpoint.
147 static GoogleServiceAuthError FromCaptchaChallenge(
148 const std::string& captcha_token,
149 const GURL& captcha_audio_url,
150 const GURL& captcha_image_url,
151 int image_width,
152 int image_height);
153
154 // Construct a TWO_FACTOR error with second-factor challenge data.
155 static GoogleServiceAuthError FromSecondFactorChallenge(
156 const std::string& captcha_token,
157 const std::string& prompt_text,
158 const std::string& alternate_text,
159 int field_length);
160
161 // Construct an INVALID_GAIA_CREDENTIALS error from a ClientOAuth response.
162 // |data| is the JSON response from the server explaning the error.
163 static GoogleServiceAuthError FromClientOAuthError(const std::string& data);
164
165 // Provided for convenience for clients needing to reset an instance to NONE.
166 // (avoids err_ = GoogleServiceAuthError(GoogleServiceAuthError::NONE), due
167 // to explicit class and State enum relation. Note: shouldn't be inlined!
168 static GoogleServiceAuthError None();
169
170 // The error information.
171 State state() const;
172 const Captcha& captcha() const;
173 const SecondFactor& second_factor() const;
174 int network_error() const;
175 const std::string& token() const;
176 const std::string& error_message() const;
177
178 // Returns info about this object in a dictionary. Caller takes
179 // ownership of returned dictionary.
180 base::DictionaryValue* ToValue() const;
181
182 // Returns a message describing the error.
183 std::string ToString() const;
184
185 private:
186 GoogleServiceAuthError(State s, int error);
187
188 explicit GoogleServiceAuthError(const std::string& error_message);
189
190 GoogleServiceAuthError(State s, const std::string& captcha_token,
191 const GURL& captcha_audio_url,
192 const GURL& captcha_image_url,
193 const GURL& captcha_unlock_url,
194 int image_width,
195 int image_height);
196
197 GoogleServiceAuthError(State s, const std::string& captcha_token,
198 const std::string& prompt_text,
199 const std::string& alternate_text,
200 int field_length);
201
202 State state_;
203 Captcha captcha_;
204 SecondFactor second_factor_;
205 int network_error_;
206 std::string error_message_;
207 };
208
209 #endif // CHROME_COMMON_NET_GAIA_GOOGLE_SERVICE_AUTH_ERROR_H_
OLDNEW
« no previous file with comments | « chrome/common/net/gaia/gaia_urls.cc ('k') | chrome/common/net/gaia/google_service_auth_error.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698