| Index: chrome/common/net/gaia/gaia_auth_fetcher.cc
|
| ===================================================================
|
| --- chrome/common/net/gaia/gaia_auth_fetcher.cc (revision 88668)
|
| +++ chrome/common/net/gaia/gaia_auth_fetcher.cc (working copy)
|
| @@ -48,6 +48,11 @@
|
| // static
|
| const char GaiaAuthFetcher::kGetUserInfoFormat[] =
|
| "LSID=%s";
|
| +// static
|
| +const char GaiaAuthFetcher::kTokenAuthFormat[] =
|
| + "auth=%s&"
|
| + "continue=%s&"
|
| + "source=%s";
|
|
|
| // static
|
| const char GaiaAuthFetcher::kAccountDeletedError[] = "AccountDeleted";
|
| @@ -93,6 +98,8 @@
|
| "https://www.google.com/accounts/IssueAuthToken";
|
| const char GaiaAuthFetcher::kGetUserInfoUrl[] =
|
| "https://www.google.com/accounts/GetUserInfo";
|
| +const char GaiaAuthFetcher::kTokenAuthUrl[] =
|
| + "https://www.google.com/accounts/TokenAuth";
|
|
|
| GaiaAuthFetcher::GaiaAuthFetcher(GaiaAuthConsumer* consumer,
|
| const std::string& source,
|
| @@ -103,6 +110,7 @@
|
| client_login_gurl_(kClientLoginUrl),
|
| issue_auth_token_gurl_(kIssueAuthTokenUrl),
|
| get_user_info_gurl_(kGetUserInfoUrl),
|
| + token_auth_gurl_(kTokenAuthUrl),
|
| fetch_pending_(false) {}
|
|
|
| GaiaAuthFetcher::~GaiaAuthFetcher() {}
|
| @@ -200,6 +208,19 @@
|
| return base::StringPrintf(kGetUserInfoFormat, encoded_lsid.c_str());
|
| }
|
|
|
| +// static
|
| +std::string GaiaAuthFetcher::MakeTokenAuthBody(const std::string& auth_token,
|
| + const std::string& continue_url,
|
| + const std::string& source) {
|
| + std::string encoded_auth_token = EscapeUrlEncodedData(auth_token);
|
| + std::string encoded_continue_url = EscapeUrlEncodedData(continue_url);
|
| + std::string encoded_source = EscapeUrlEncodedData(source);
|
| + return base::StringPrintf(kTokenAuthFormat,
|
| + encoded_auth_token.c_str(),
|
| + encoded_continue_url.c_str(),
|
| + encoded_source.c_str());
|
| +}
|
| +
|
| // Helper method that extracts tokens from a successful reply.
|
| // static
|
| void GaiaAuthFetcher::ParseClientLoginResponse(const std::string& data,
|
| @@ -312,6 +333,24 @@
|
| fetcher_->Start();
|
| }
|
|
|
| +void GaiaAuthFetcher::StartTokenAuth(const std::string& auth_token) {
|
| + DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
|
| +
|
| + VLOG(1) << "Starting TokenAuth with auth_token=" << auth_token;
|
| +
|
| + // The continue URL is a required parameter of the TokenAuth API, but in this
|
| + // case we don't actually need or want to navigate to it. Setting it to
|
| + // an arbitrary Google URL.
|
| + std::string continue_url("http://www.google.com");
|
| + request_body_ = MakeTokenAuthBody(auth_token, continue_url, source_);
|
| + fetcher_.reset(CreateGaiaFetcher(getter_,
|
| + request_body_,
|
| + token_auth_gurl_,
|
| + this));
|
| + fetch_pending_ = true;
|
| + fetcher_->Start();
|
| +}
|
| +
|
| // static
|
| GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError(
|
| const std::string& data,
|
| @@ -418,6 +457,16 @@
|
| }
|
| }
|
|
|
| +void GaiaAuthFetcher::OnTokenAuthFetched(const std::string& data,
|
| + const net::URLRequestStatus& status,
|
| + int response_code) {
|
| + if (status.is_success() && response_code == RC_REQUEST_OK) {
|
| + consumer_->OnTokenAuthSuccess(data);
|
| + } else {
|
| + consumer_->OnTokenAuthFailure(GenerateAuthError(data, status));
|
| + }
|
| +}
|
| +
|
| void GaiaAuthFetcher::OnURLFetchComplete(const URLFetcher* source,
|
| const GURL& url,
|
| const net::URLRequestStatus& status,
|
| @@ -431,6 +480,8 @@
|
| OnIssueAuthTokenFetched(data, status, response_code);
|
| } else if (url == get_user_info_gurl_) {
|
| OnGetUserInfoFetched(data, status, response_code);
|
| + } else if (url == token_auth_gurl_) {
|
| + OnTokenAuthFetched(data, status, response_code);
|
| } else {
|
| NOTREACHED();
|
| }
|
|
|