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

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

Issue 7121014: When a user logs into sync, the appropriate cookies are retrieved so that (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixing merge issue that caused previous trybots to fail Created 9 years, 6 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ 5 #ifndef CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_
6 #define CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ 6 #define CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 19 matching lines...) Expand all
30 public: 30 public:
31 enum HostedAccountsSetting { 31 enum HostedAccountsSetting {
32 HostedAccountsAllowed, 32 HostedAccountsAllowed,
33 HostedAccountsNotAllowed 33 HostedAccountsNotAllowed
34 }; 34 };
35 35
36 // The URLs for different calls in the Google Accounts programmatic login API. 36 // The URLs for different calls in the Google Accounts programmatic login API.
37 static const char kClientLoginUrl[]; 37 static const char kClientLoginUrl[];
38 static const char kIssueAuthTokenUrl[]; 38 static const char kIssueAuthTokenUrl[];
39 static const char kGetUserInfoUrl[]; 39 static const char kGetUserInfoUrl[];
40 static const char kTokenAuthUrl[];
40 41
41 // Magic string indicating that, while a second factor is still 42 // Magic string indicating that, while a second factor is still
42 // needed to complete authentication, the user provided the right password. 43 // needed to complete authentication, the user provided the right password.
43 static const char kSecondFactor[]; 44 static const char kSecondFactor[];
44 45
45 // This will later be hidden behind an auth service which caches 46 // This will later be hidden behind an auth service which caches
46 // tokens. 47 // tokens.
47 GaiaAuthFetcher(GaiaAuthConsumer* consumer, 48 GaiaAuthFetcher(GaiaAuthConsumer* consumer,
48 const std::string& source, 49 const std::string& source,
49 net::URLRequestContextGetter* getter); 50 net::URLRequestContextGetter* getter);
(...skipping 16 matching lines...) Expand all
66 const std::string& lsid, 67 const std::string& lsid,
67 const char* const service); 68 const char* const service);
68 69
69 // Start a request to get a particular key from user info. 70 // Start a request to get a particular key from user info.
70 // GaiaAuthConsumer will be called back on the same thread when 71 // GaiaAuthConsumer will be called back on the same thread when
71 // results come back. 72 // results come back.
72 // You can't make more than one request at a time. 73 // You can't make more than one request at a time.
73 void StartGetUserInfo(const std::string& lsid, 74 void StartGetUserInfo(const std::string& lsid,
74 const std::string& info_key); 75 const std::string& info_key);
75 76
77 // Start a TokenAuth request to pre-login the user with the given credentials.
78 void StartTokenAuth(const std::string& auth_token);
79
76 // Implementation of URLFetcher::Delegate 80 // Implementation of URLFetcher::Delegate
77 virtual void OnURLFetchComplete(const URLFetcher* source, 81 virtual void OnURLFetchComplete(const URLFetcher* source,
78 const GURL& url, 82 const GURL& url,
79 const net::URLRequestStatus& status, 83 const net::URLRequestStatus& status,
80 int response_code, 84 int response_code,
81 const net::ResponseCookies& cookies, 85 const net::ResponseCookies& cookies,
82 const std::string& data); 86 const std::string& data);
83 87
84 // StartClientLogin been called && results not back yet? 88 // StartClientLogin been called && results not back yet?
85 bool HasPendingFetch(); 89 bool HasPendingFetch();
86 90
87 // Stop any URL fetches in progress. 91 // Stop any URL fetches in progress.
88 void CancelRequest(); 92 void CancelRequest();
89 93
90 private: 94 private:
91 // ClientLogin body constants that don't change 95 // ClientLogin body constants that don't change
92 static const char kCookiePersistence[]; 96 static const char kCookiePersistence[];
93 static const char kAccountTypeHostedOrGoogle[]; 97 static const char kAccountTypeHostedOrGoogle[];
94 static const char kAccountTypeGoogle[]; 98 static const char kAccountTypeGoogle[];
95 99
96 // The format of the POST body for ClientLogin. 100 // The format of the POST body for ClientLogin.
97 static const char kClientLoginFormat[]; 101 static const char kClientLoginFormat[];
98 // The format of said POST body when CAPTCHA token & answer are specified. 102 // The format of said POST body when CAPTCHA token & answer are specified.
99 static const char kClientLoginCaptchaFormat[]; 103 static const char kClientLoginCaptchaFormat[];
100 // The format of the POST body for IssueAuthToken. 104 // The format of the POST body for IssueAuthToken.
101 static const char kIssueAuthTokenFormat[]; 105 static const char kIssueAuthTokenFormat[];
102 // The format of the POSt body for GetUserInfo. 106 // The format of the POST body for GetUserInfo.
103 static const char kGetUserInfoFormat[]; 107 static const char kGetUserInfoFormat[];
108 // The format of the POST body for TokenAuth.
109 static const char GaiaAuthFetcher::kTokenAuthFormat[];
104 110
105 // Constants for parsing ClientLogin errors. 111 // Constants for parsing ClientLogin errors.
106 static const char kAccountDeletedError[]; 112 static const char kAccountDeletedError[];
107 static const char kAccountDisabledError[]; 113 static const char kAccountDisabledError[];
108 static const char kBadAuthenticationError[]; 114 static const char kBadAuthenticationError[];
109 static const char kCaptchaError[]; 115 static const char kCaptchaError[];
110 static const char kServiceUnavailableError[]; 116 static const char kServiceUnavailableError[];
111 static const char kErrorParam[]; 117 static const char kErrorParam[];
112 static const char kErrorUrlParam[]; 118 static const char kErrorUrlParam[];
113 static const char kCaptchaUrlParam[]; 119 static const char kCaptchaUrlParam[];
114 static const char kCaptchaTokenParam[]; 120 static const char kCaptchaTokenParam[];
115 static const char kCaptchaUrlPrefix[]; 121 static const char kCaptchaUrlPrefix[];
116 122
117 // Process the results of a ClientLogin fetch. 123 // Process the results of a ClientLogin fetch.
118 void OnClientLoginFetched(const std::string& data, 124 void OnClientLoginFetched(const std::string& data,
119 const net::URLRequestStatus& status, 125 const net::URLRequestStatus& status,
120 int response_code); 126 int response_code);
121 127
122 void OnIssueAuthTokenFetched(const std::string& data, 128 void OnIssueAuthTokenFetched(const std::string& data,
123 const net::URLRequestStatus& status, 129 const net::URLRequestStatus& status,
124 int response_code); 130 int response_code);
125 131
126 void OnGetUserInfoFetched(const std::string& data, 132 void OnGetUserInfoFetched(const std::string& data,
127 const net::URLRequestStatus& status, 133 const net::URLRequestStatus& status,
128 int response_code); 134 int response_code);
129 135
136 void OnTokenAuthFetched(const std::string& data,
137 const net::URLRequestStatus& status,
138 int response_code);
139
130 // Tokenize the results of a ClientLogin fetch. 140 // Tokenize the results of a ClientLogin fetch.
131 static void ParseClientLoginResponse(const std::string& data, 141 static void ParseClientLoginResponse(const std::string& data,
132 std::string* sid, 142 std::string* sid,
133 std::string* lsid, 143 std::string* lsid,
134 std::string* token); 144 std::string* token);
135 145
136 static void ParseClientLoginFailure(const std::string& data, 146 static void ParseClientLoginFailure(const std::string& data,
137 std::string* error, 147 std::string* error,
138 std::string* error_url, 148 std::string* error_url,
139 std::string* captcha_url, 149 std::string* captcha_url,
(...skipping 20 matching lines...) Expand all
160 HostedAccountsSetting allow_hosted_accounts); 170 HostedAccountsSetting allow_hosted_accounts);
161 // Supply the sid / lsid returned from ClientLogin in order to 171 // Supply the sid / lsid returned from ClientLogin in order to
162 // request a long lived auth token for a service. 172 // request a long lived auth token for a service.
163 static std::string MakeIssueAuthTokenBody(const std::string& sid, 173 static std::string MakeIssueAuthTokenBody(const std::string& sid,
164 const std::string& lsid, 174 const std::string& lsid,
165 const char* const service); 175 const char* const service);
166 // Supply the lsid returned from ClientLogin in order to fetch 176 // Supply the lsid returned from ClientLogin in order to fetch
167 // user information. 177 // user information.
168 static std::string MakeGetUserInfoBody(const std::string& lsid); 178 static std::string MakeGetUserInfoBody(const std::string& lsid);
169 179
180 // Supply the authentication token returned from StartIssueAuthToken.
181 static std::string MakeTokenAuthBody(const std::string& auth_token,
182 const std::string& continue_url,
183 const std::string& source);
184
170 // Create a fetcher useable for making any Gaia request. 185 // Create a fetcher useable for making any Gaia request.
171 static URLFetcher* CreateGaiaFetcher(net::URLRequestContextGetter* getter, 186 static URLFetcher* CreateGaiaFetcher(net::URLRequestContextGetter* getter,
172 const std::string& body, 187 const std::string& body,
173 const GURL& gaia_gurl_, 188 const GURL& gaia_gurl_,
174 URLFetcher::Delegate* delegate); 189 URLFetcher::Delegate* delegate);
175 190
176 191
177 // These fields are common to GaiaAuthFetcher, same every request 192 // These fields are common to GaiaAuthFetcher, same every request
178 GaiaAuthConsumer* const consumer_; 193 GaiaAuthConsumer* const consumer_;
179 net::URLRequestContextGetter* const getter_; 194 net::URLRequestContextGetter* const getter_;
180 std::string source_; 195 std::string source_;
181 const GURL client_login_gurl_; 196 const GURL client_login_gurl_;
182 const GURL issue_auth_token_gurl_; 197 const GURL issue_auth_token_gurl_;
183 const GURL get_user_info_gurl_; 198 const GURL get_user_info_gurl_;
199 const GURL token_auth_gurl_;
184 200
185 // While a fetch is going on: 201 // While a fetch is going on:
186 scoped_ptr<URLFetcher> fetcher_; 202 scoped_ptr<URLFetcher> fetcher_;
187 std::string request_body_; 203 std::string request_body_;
188 std::string requested_service_; // Currently tracked for IssueAuthToken only 204 std::string requested_service_; // Currently tracked for IssueAuthToken only
189 std::string requested_info_key_; // Currently tracked for GetUserInfo only 205 std::string requested_info_key_; // Currently tracked for GetUserInfo only
190 bool fetch_pending_; 206 bool fetch_pending_;
191 207
192 friend class GaiaAuthFetcherTest; 208 friend class GaiaAuthFetcherTest;
193 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CaptchaParse); 209 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CaptchaParse);
194 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDeletedError); 210 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDeletedError);
195 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDisabledError); 211 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, AccountDisabledError);
196 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, BadAuthenticationError); 212 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, BadAuthenticationError);
197 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, IncomprehensibleError); 213 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, IncomprehensibleError);
198 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ServiceUnavailableError); 214 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ServiceUnavailableError);
199 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckNormalErrorCode); 215 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckNormalErrorCode);
200 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckTwoFactorResponse); 216 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckTwoFactorResponse);
201 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, LoginNetFailure); 217 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, LoginNetFailure);
202 218
203 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); 219 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher);
204 }; 220 };
205 221
206 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ 222 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698