OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include <vector> | 10 #include <vector> |
(...skipping 12 matching lines...) Expand all Loading... |
23 // that you like. | 23 // that you like. |
24 // | 24 // |
25 // This class can handle one request at a time. To parallelize requests, | 25 // This class can handle one request at a time. To parallelize requests, |
26 // create multiple GaiaAuthFetcher's. | 26 // create multiple GaiaAuthFetcher's. |
27 | 27 |
28 class GaiaAuthFetcherTest; | 28 class GaiaAuthFetcherTest; |
29 | 29 |
30 namespace net { | 30 namespace net { |
31 class URLRequestContextGetter; | 31 class URLRequestContextGetter; |
32 class URLRequestStatus; | 32 class URLRequestStatus; |
33 typedef std::vector<std::string> ResponseCookies; | |
34 } | 33 } |
35 | 34 |
36 class GaiaAuthFetcher : public content::URLFetcherDelegate { | 35 class GaiaAuthFetcher : public content::URLFetcherDelegate { |
37 public: | 36 public: |
38 enum HostedAccountsSetting { | 37 enum HostedAccountsSetting { |
39 HostedAccountsAllowed, | 38 HostedAccountsAllowed, |
40 HostedAccountsNotAllowed | 39 HostedAccountsNotAllowed |
41 }; | 40 }; |
42 | 41 |
43 // Magic string indicating that, while a second factor is still | 42 // Magic string indicating that, while a second factor is still |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 81 |
83 // Start a TokenAuth request to pre-login the user with the given credentials. | 82 // Start a TokenAuth request to pre-login the user with the given credentials. |
84 void StartTokenAuth(const std::string& auth_token); | 83 void StartTokenAuth(const std::string& auth_token); |
85 | 84 |
86 // Start a MergeSession request to pre-login the user with the given | 85 // Start a MergeSession request to pre-login the user with the given |
87 // credentials. Unlike TokenAuth above, MergeSession will not sign out any | 86 // credentials. Unlike TokenAuth above, MergeSession will not sign out any |
88 // existing accounts. | 87 // existing accounts. |
89 void StartMergeSession(const std::string& auth_token); | 88 void StartMergeSession(const std::string& auth_token); |
90 | 89 |
91 // Start a request to get an uber-auth token. The given |access_token| must | 90 // Start a request to get an uber-auth token. The given |access_token| must |
92 // be an OAuth2 valid access token. | 91 // be an OAuth2 valid access token. If |access_token| is an empty string, |
| 92 // then the cookie jar is used with the request. |
93 void StartUberAuthTokenFetch(const std::string& access_token); | 93 void StartUberAuthTokenFetch(const std::string& access_token); |
94 | 94 |
95 // Implementation of content::URLFetcherDelegate | 95 // Implementation of content::URLFetcherDelegate |
96 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 96 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
97 | 97 |
98 // StartClientLogin been called && results not back yet? | 98 // StartClientLogin been called && results not back yet? |
99 bool HasPendingFetch(); | 99 bool HasPendingFetch(); |
100 | 100 |
101 // Stop any URL fetches in progress. | 101 // Stop any URL fetches in progress. |
102 void CancelRequest(); | 102 void CancelRequest(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 int response_code); | 175 int response_code); |
176 | 176 |
177 void OnOAuth2TokenPairFetched(const std::string& data, | 177 void OnOAuth2TokenPairFetched(const std::string& data, |
178 const net::URLRequestStatus& status, | 178 const net::URLRequestStatus& status, |
179 int response_code); | 179 int response_code); |
180 | 180 |
181 void OnGetUserInfoFetched(const std::string& data, | 181 void OnGetUserInfoFetched(const std::string& data, |
182 const net::URLRequestStatus& status, | 182 const net::URLRequestStatus& status, |
183 int response_code); | 183 int response_code); |
184 | 184 |
185 void OnTokenAuthFetched(const std::string& data, | 185 void OnTokenAuthFetched(const net::ResponseCookies& cookies, |
| 186 const std::string& data, |
186 const net::URLRequestStatus& status, | 187 const net::URLRequestStatus& status, |
187 int response_code); | 188 int response_code); |
188 | 189 |
189 void OnMergeSessionFetched(const std::string& data, | 190 void OnMergeSessionFetched(const std::string& data, |
190 const net::URLRequestStatus& status, | 191 const net::URLRequestStatus& status, |
191 int response_code); | 192 int response_code); |
192 | 193 |
193 void OnUberAuthTokenFetch(const std::string& data, | 194 void OnUberAuthTokenFetch(const std::string& data, |
194 const net::URLRequestStatus& status, | 195 const net::URLRequestStatus& status, |
195 int response_code); | 196 int response_code); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 253 |
253 // Supply the authentication token returned from StartIssueAuthToken. | 254 // Supply the authentication token returned from StartIssueAuthToken. |
254 static std::string MakeMergeSessionBody(const std::string& auth_token, | 255 static std::string MakeMergeSessionBody(const std::string& auth_token, |
255 const std::string& continue_url, | 256 const std::string& continue_url, |
256 const std::string& source); | 257 const std::string& source); |
257 | 258 |
258 static std::string MakeGetAuthCodeHeader(const std::string& auth_token); | 259 static std::string MakeGetAuthCodeHeader(const std::string& auth_token); |
259 | 260 |
260 void StartOAuth2TokenPairFetch(const std::string& auth_code); | 261 void StartOAuth2TokenPairFetch(const std::string& auth_code); |
261 | 262 |
262 // Create a fetcher useable for making any Gaia request. | 263 // Create a fetcher usable for making any Gaia request. |body| is used |
| 264 // as the body of the POST request sent to GAIA. Any strings listed in |
| 265 // |headers| are added as extra HTTP headers in the request. |
| 266 // |
| 267 // |load_flags| are passed to directly to content::URLFetcher::Create() when |
| 268 // creating the URL fetcher. |
263 static content::URLFetcher* CreateGaiaFetcher( | 269 static content::URLFetcher* CreateGaiaFetcher( |
264 net::URLRequestContextGetter* getter, | 270 net::URLRequestContextGetter* getter, |
265 const std::string& body, | 271 const std::string& body, |
266 const std::string& headers, | 272 const std::string& headers, |
267 const GURL& gaia_gurl, | 273 const GURL& gaia_gurl, |
268 bool use_cookies, | 274 int load_flags, |
269 content::URLFetcherDelegate* delegate); | 275 content::URLFetcherDelegate* delegate); |
270 | 276 |
271 // From a URLFetcher result, generate an appropriate error. | 277 // From a URLFetcher result, generate an appropriate error. |
272 // From the API documentation, both IssueAuthToken and ClientLogin have | 278 // From the API documentation, both IssueAuthToken and ClientLogin have |
273 // the same error returns. | 279 // the same error returns. |
274 static GoogleServiceAuthError GenerateAuthError( | 280 static GoogleServiceAuthError GenerateAuthError( |
275 const std::string& data, | 281 const std::string& data, |
276 const net::URLRequestStatus& status); | 282 const net::URLRequestStatus& status); |
277 | 283 |
278 // These fields are common to GaiaAuthFetcher, same every request | 284 // These fields are common to GaiaAuthFetcher, same every request |
(...skipping 26 matching lines...) Expand all Loading... |
305 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckTwoFactorResponse); | 311 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, CheckTwoFactorResponse); |
306 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, LoginNetFailure); | 312 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, LoginNetFailure); |
307 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, | 313 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, |
308 ParseClientLoginToOAuth2Response); | 314 ParseClientLoginToOAuth2Response); |
309 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ParseOAuth2TokenPairResponse); | 315 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ParseOAuth2TokenPairResponse); |
310 | 316 |
311 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); | 317 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); |
312 }; | 318 }; |
313 | 319 |
314 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ | 320 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_H_ |
OLD | NEW |