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

Unified Diff: chrome/common/net/gaia/gaia_authenticator2.h

Issue 2834042: Add IssueAuthToken and unit tests to GaiaAuthenticator2. (Closed)
Patch Set: Created 10 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/net/gaia/gaia_authenticator2.h
diff --git a/chrome/common/net/gaia/gaia_authenticator2.h b/chrome/common/net/gaia/gaia_authenticator2.h
index bbb3761c5d0309d26c17dee31d88af2209460660..57ea5a3d0b3910f09c9a68dc7d5a832b1f879e41 100644
--- a/chrome/common/net/gaia/gaia_authenticator2.h
+++ b/chrome/common/net/gaia/gaia_authenticator2.h
@@ -8,6 +8,7 @@
#include <string>
#include "base/gtest_prod_util.h"
+#include "chrome/common/net/gaia/gaia_auth_consumer.h"
#include "chrome/common/net/url_fetcher.h"
#include "googleurl/src/gurl.h"
@@ -17,8 +18,10 @@
// In the future, we will also issue auth tokens from this class.
// This class should be used on a single thread, but it can be whichever thread
// that you like.
+//
+// This class can handle one request at a time. To parallelize requests,
+// create multiple GaiaAuthenticator2's.
-class GaiaAuthConsumer;
class GaiaAuthenticator2Test;
class GaiaAuthenticator2 : public URLFetcher::Delegate {
@@ -30,8 +33,6 @@ class GaiaAuthenticator2 : public URLFetcher::Delegate {
// The URLs for different calls in the Google Accounts programmatic login API.
static const char kClientLoginUrl[];
static const char kIssueAuthTokenUrl[];
- static const char kTokenAuthUrl[];
-
// Magic string indicating that, while a second factor is still
// needed to complete authentication, the user provided the right password.
@@ -46,12 +47,20 @@ class GaiaAuthenticator2 : public URLFetcher::Delegate {
// GaiaAuthConsumer will be called on the original thread
// after results come back. This class is thread agnostic.
+ // You can't make more than request at a time.
void StartClientLogin(const std::string& username,
const std::string& password,
const char* const service,
const std::string& login_token,
const std::string& login_captcha);
+ // GaiaAuthConsumer will be called on the original thread
+ // after results come back. This class is thread agnostic.
+ // You can't make more than one request at a time.
+ void StartIssueAuthToken(const std::string& sid,
+ const std::string& lsid,
+ const char* const service);
+
// Implementation of URLFetcher::Delegate
void OnURLFetchComplete(const URLFetcher* source,
const GURL& url,
@@ -75,41 +84,64 @@ class GaiaAuthenticator2 : public URLFetcher::Delegate {
static const char kClientLoginFormat[];
// The format of said POST body when CAPTCHA token & answer are specified.
static const char kClientLoginCaptchaFormat[];
+ // The format of the POST body for IssueAuthToken.
+ static const char kIssueAuthTokenFormat[];
// Process the results of a ClientLogin fetch.
void OnClientLoginFetched(const std::string& data,
const URLRequestStatus& status,
int response_code);
+ void OnIssueAuthTokenFetched(const std::string& data,
+ const URLRequestStatus& status,
+ int response_code);
+
// Tokenize the results of a ClientLogin fetch.
static void ParseClientLoginResponse(const std::string& data,
std::string* sid,
std::string* lsid,
std::string* token);
+ // From a URLFetcher result, generate an appropriate GaiaAuthError.
+ // From the API documentation, both IssueAuthToken and ClientLogin have
+ // the same error returns.
+ static GaiaAuthConsumer::GaiaAuthError GenerateAuthError(
+ const std::string& data,
+ const URLRequestStatus& status);
+
// Is this a special case Gaia error for TwoFactor auth?
static bool IsSecondFactorSuccess(const std::string& alleged_error);
// Given parameters, create a ClientLogin request body.
- static std::string GenerateRequestBody(const std::string& username,
+ static std::string MakeClientLoginBody(const std::string& username,
const std::string& password,
const std::string& source,
- const char* service,
+ const char* const service,
const std::string& login_token,
const std::string& login_captcha);
- // Create a fetcher useable for making a ClientLogin request.
- static URLFetcher* CreateClientLoginFetcher(URLRequestContextGetter* getter,
- const std::string& body,
- const GURL& client_login_gurl_,
- URLFetcher::Delegate* delegate);
+ static std::string MakeIssueAuthTokenBody(const std::string& sid,
+ const std::string& lsid,
+ const char* const service);
+
+ // Create a fetcher useable for making any Gaia request.
+ static URLFetcher* CreateGaiaFetcher(URLRequestContextGetter* getter,
+ const std::string& body,
+ const GURL& gaia_gurl_,
+ URLFetcher::Delegate* delegate);
+
+ // Unique per GaiaAuthenticator2
GaiaAuthConsumer* const consumer_;
- scoped_ptr<URLFetcher> fetcher_;
URLRequestContextGetter* const getter_;
std::string source_;
const GURL client_login_gurl_;
+ const GURL issue_auth_token_gurl_;
+
+ // While a fetch is going on:
+ scoped_ptr<URLFetcher> fetcher_;
std::string request_body_;
+ std::string requested_service_; // Currently tracked for IssueAuthToken only
bool fetch_pending_;
friend class GaiaAuthenticator2Test;

Powered by Google App Engine
This is Rietveld 408576698