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 GOOGLE_APIS_GAIA_GAIA_AUTH_FETCHER_H_ | 5 #ifndef GOOGLE_APIS_GAIA_GAIA_AUTH_FETCHER_H_ |
6 #define GOOGLE_APIS_GAIA_GAIA_AUTH_FETCHER_H_ | 6 #define GOOGLE_APIS_GAIA_GAIA_AUTH_FETCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 void StartMergeSession(const std::string& uber_token); | 140 void StartMergeSession(const std::string& uber_token); |
141 | 141 |
142 // Start a request to exchange an OAuthLogin-scoped oauth2 access token for an | 142 // Start a request to exchange an OAuthLogin-scoped oauth2 access token for an |
143 // uber-auth token. The returned token can be used with the method | 143 // uber-auth token. The returned token can be used with the method |
144 // StartMergeSession(). | 144 // StartMergeSession(). |
145 // | 145 // |
146 // Either OnUberAuthTokenSuccess or OnUberAuthTokenFailure will be | 146 // Either OnUberAuthTokenSuccess or OnUberAuthTokenFailure will be |
147 // called on the consumer on the original thread. | 147 // called on the consumer on the original thread. |
148 void StartTokenFetchForUberAuthExchange(const std::string& access_token); | 148 void StartTokenFetchForUberAuthExchange(const std::string& access_token); |
149 | 149 |
150 // Start a request to obtain an OAuth2 token for the account identified by | |
151 // |username| and |password|. |scopes| is a list of oauth scopes that | |
152 // indicate the access permerssions to assign to the returned token. | |
153 // |persistent_id| is an optional client identifier used to identify this | |
154 // particular chrome instances, which may reduce the chance of a challenge. | |
155 // |locale| will be used to format messages to be presented to the user in | |
156 // challenges, if needed. | |
157 // | |
158 // If the request cannot complete due to a challenge, the | |
159 // GoogleServiceAuthError will indicate the type of challenge required: | |
160 // either CAPTCHA_REQUIRED or TWO_FACTOR. | |
161 // | |
162 // Either OnClientOAuthSuccess or OnClientOAuthFailure will be | |
163 // called on the consumer on the original thread. | |
164 void StartClientOAuth(const std::string& username, | |
165 const std::string& password, | |
166 const std::vector<std::string>& scopes, | |
167 const std::string& persistent_id, | |
168 const std::string& locale); | |
169 | |
170 // Start a challenge response to obtain an OAuth2 token. This method is | |
171 // called after a challenge response is issued from a previous call to | |
172 // StartClientOAuth(). The |type| and |token| arguments come from the | |
173 // error response to StartClientOAuth(), while the |solution| argument | |
174 // represents the answer from the user for the partocular challenge. | |
175 // | |
176 // Either OnClientOAuthSuccess or OnClientOAuthFailure will be | |
177 // called on the consumer on the original thread. | |
178 void StartClientOAuthChallengeResponse(GoogleServiceAuthError::State type, | |
179 const std::string& token, | |
180 const std::string& solution); | |
181 | |
182 // Start a request to exchange an OAuthLogin-scoped oauth2 access token for a | 150 // Start a request to exchange an OAuthLogin-scoped oauth2 access token for a |
183 // ClientLogin-style service tokens. The response to this request is the | 151 // ClientLogin-style service tokens. The response to this request is the |
184 // same as the response to a ClientLogin request, except that captcha | 152 // same as the response to a ClientLogin request, except that captcha |
185 // challenges are never issued. | 153 // challenges are never issued. |
186 // | 154 // |
187 // Either OnClientLoginSuccess or OnClientLoginFailure will be | 155 // Either OnClientLoginSuccess or OnClientLoginFailure will be |
188 // called on the consumer on the original thread. If |service| is empty, | 156 // called on the consumer on the original thread. If |service| is empty, |
189 // the call will attempt to fetch uber auth token. | 157 // the call will attempt to fetch uber auth token. |
190 void StartOAuthLogin(const std::string& access_token, | 158 void StartOAuthLogin(const std::string& access_token, |
191 const std::string& service); | 159 const std::string& service); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 int response_code); | 258 int response_code); |
291 | 259 |
292 void OnMergeSessionFetched(const std::string& data, | 260 void OnMergeSessionFetched(const std::string& data, |
293 const net::URLRequestStatus& status, | 261 const net::URLRequestStatus& status, |
294 int response_code); | 262 int response_code); |
295 | 263 |
296 void OnUberAuthTokenFetch(const std::string& data, | 264 void OnUberAuthTokenFetch(const std::string& data, |
297 const net::URLRequestStatus& status, | 265 const net::URLRequestStatus& status, |
298 int response_code); | 266 int response_code); |
299 | 267 |
300 void OnClientOAuthFetched(const std::string& data, | |
301 const net::URLRequestStatus& status, | |
302 int response_code); | |
303 | |
304 void OnOAuthLoginFetched(const std::string& data, | 268 void OnOAuthLoginFetched(const std::string& data, |
305 const net::URLRequestStatus& status, | 269 const net::URLRequestStatus& status, |
306 int response_code); | 270 int response_code); |
307 | 271 |
308 // Tokenize the results of a ClientLogin fetch. | 272 // Tokenize the results of a ClientLogin fetch. |
309 static void ParseClientLoginResponse(const std::string& data, | 273 static void ParseClientLoginResponse(const std::string& data, |
310 std::string* sid, | 274 std::string* sid, |
311 std::string* lsid, | 275 std::string* lsid, |
312 std::string* token); | 276 std::string* token); |
313 | 277 |
314 static void ParseClientLoginFailure(const std::string& data, | 278 static void ParseClientLoginFailure(const std::string& data, |
315 std::string* error, | 279 std::string* error, |
316 std::string* error_url, | 280 std::string* error_url, |
317 std::string* captcha_url, | 281 std::string* captcha_url, |
318 std::string* captcha_token); | 282 std::string* captcha_token); |
319 | 283 |
320 // Parse ClientLogin to OAuth2 response. | 284 // Parse ClientLogin to OAuth2 response. |
321 static bool ParseClientLoginToOAuth2Response( | 285 static bool ParseClientLoginToOAuth2Response( |
322 const net::ResponseCookies& cookies, | 286 const net::ResponseCookies& cookies, |
323 std::string* auth_code); | 287 std::string* auth_code); |
324 | 288 |
325 static bool ParseClientLoginToOAuth2Cookie(const std::string& cookie, | 289 static bool ParseClientLoginToOAuth2Cookie(const std::string& cookie, |
326 std::string* auth_code); | 290 std::string* auth_code); |
327 | 291 |
328 static GoogleServiceAuthError GenerateClientOAuthError( | |
329 const std::string& data, | |
330 const net::URLRequestStatus& status); | |
331 | |
332 // Is this a special case Gaia error for TwoFactor auth? | 292 // Is this a special case Gaia error for TwoFactor auth? |
333 static bool IsSecondFactorSuccess(const std::string& alleged_error); | 293 static bool IsSecondFactorSuccess(const std::string& alleged_error); |
334 | 294 |
335 // Given parameters, create a ClientLogin request body. | 295 // Given parameters, create a ClientLogin request body. |
336 static std::string MakeClientLoginBody( | 296 static std::string MakeClientLoginBody( |
337 const std::string& username, | 297 const std::string& username, |
338 const std::string& password, | 298 const std::string& password, |
339 const std::string& source, | 299 const std::string& source, |
340 const char* const service, | 300 const char* const service, |
341 const std::string& login_token, | 301 const std::string& login_token, |
(...skipping 14 matching lines...) Expand all Loading... |
356 // user information. | 316 // user information. |
357 static std::string MakeGetUserInfoBody(const std::string& lsid); | 317 static std::string MakeGetUserInfoBody(const std::string& lsid); |
358 | 318 |
359 // Supply the authentication token returned from StartIssueAuthToken. | 319 // Supply the authentication token returned from StartIssueAuthToken. |
360 static std::string MakeMergeSessionBody(const std::string& auth_token, | 320 static std::string MakeMergeSessionBody(const std::string& auth_token, |
361 const std::string& continue_url, | 321 const std::string& continue_url, |
362 const std::string& source); | 322 const std::string& source); |
363 | 323 |
364 static std::string MakeGetAuthCodeHeader(const std::string& auth_token); | 324 static std::string MakeGetAuthCodeHeader(const std::string& auth_token); |
365 | 325 |
366 static std::string MakeClientOAuthBody(const std::string& username, | |
367 const std::string& password, | |
368 const std::vector<std::string>& scopes, | |
369 const std::string& persistent_id, | |
370 const std::string& friendly_name, | |
371 const std::string& locale); | |
372 | |
373 static std::string MakeClientOAuthChallengeResponseBody( | |
374 const std::string& name, | |
375 const std::string& token, | |
376 const std::string& solution); | |
377 | |
378 static std::string MakeOAuthLoginBody(const std::string& service, | 326 static std::string MakeOAuthLoginBody(const std::string& service, |
379 const std::string& source); | 327 const std::string& source); |
380 | 328 |
381 // Create a fetcher usable for making any Gaia request. |body| is used | 329 // Create a fetcher usable for making any Gaia request. |body| is used |
382 // as the body of the POST request sent to GAIA. Any strings listed in | 330 // as the body of the POST request sent to GAIA. Any strings listed in |
383 // |headers| are added as extra HTTP headers in the request. | 331 // |headers| are added as extra HTTP headers in the request. |
384 // | 332 // |
385 // |load_flags| are passed to directly to net::URLFetcher::Create() when | 333 // |load_flags| are passed to directly to net::URLFetcher::Create() when |
386 // creating the URL fetcher. | 334 // creating the URL fetcher. |
387 static net::URLFetcher* CreateGaiaFetcher( | 335 static net::URLFetcher* CreateGaiaFetcher( |
(...skipping 15 matching lines...) Expand all Loading... |
403 GaiaAuthConsumer* const consumer_; | 351 GaiaAuthConsumer* const consumer_; |
404 net::URLRequestContextGetter* const getter_; | 352 net::URLRequestContextGetter* const getter_; |
405 std::string source_; | 353 std::string source_; |
406 const GURL client_login_gurl_; | 354 const GURL client_login_gurl_; |
407 const GURL issue_auth_token_gurl_; | 355 const GURL issue_auth_token_gurl_; |
408 const GURL oauth2_token_gurl_; | 356 const GURL oauth2_token_gurl_; |
409 const GURL oauth2_revoke_gurl_; | 357 const GURL oauth2_revoke_gurl_; |
410 const GURL get_user_info_gurl_; | 358 const GURL get_user_info_gurl_; |
411 const GURL merge_session_gurl_; | 359 const GURL merge_session_gurl_; |
412 const GURL uberauth_token_gurl_; | 360 const GURL uberauth_token_gurl_; |
413 const GURL client_oauth_gurl_; | |
414 const GURL oauth_login_gurl_; | 361 const GURL oauth_login_gurl_; |
415 | 362 |
416 // While a fetch is going on: | 363 // While a fetch is going on: |
417 scoped_ptr<net::URLFetcher> fetcher_; | 364 scoped_ptr<net::URLFetcher> fetcher_; |
418 GURL client_login_to_oauth2_gurl_; | 365 GURL client_login_to_oauth2_gurl_; |
419 std::string request_body_; | 366 std::string request_body_; |
420 std::string requested_service_; // Currently tracked for IssueAuthToken only. | 367 std::string requested_service_; // Currently tracked for IssueAuthToken only. |
421 bool fetch_pending_; | 368 bool fetch_pending_; |
422 | 369 |
423 friend class GaiaAuthFetcherTest; | 370 friend class GaiaAuthFetcherTest; |
(...skipping 11 matching lines...) Expand all Loading... |
435 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ParseOAuth2TokenPairResponse); | 382 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ParseOAuth2TokenPairResponse); |
436 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ClientOAuthSuccess); | 383 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ClientOAuthSuccess); |
437 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ClientOAuthWithQuote); | 384 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ClientOAuthWithQuote); |
438 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ClientOAuthChallengeSuccess); | 385 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ClientOAuthChallengeSuccess); |
439 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ClientOAuthChallengeQuote); | 386 FRIEND_TEST_ALL_PREFIXES(GaiaAuthFetcherTest, ClientOAuthChallengeQuote); |
440 | 387 |
441 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); | 388 DISALLOW_COPY_AND_ASSIGN(GaiaAuthFetcher); |
442 }; | 389 }; |
443 | 390 |
444 #endif // GOOGLE_APIS_GAIA_GAIA_AUTH_FETCHER_H_ | 391 #endif // GOOGLE_APIS_GAIA_GAIA_AUTH_FETCHER_H_ |
OLD | NEW |