Skip to content

Commit

Permalink
Revert "Implement the calls to GAIA for the IDP IFrame protocol."
Browse files Browse the repository at this point in the history
Remove unused code in gaia_apis.

This reverts commit efc601e.
It was reviewed here: https://codereview.chromium.org/973953002.

Bug: 787260
Change-Id: If8ee0b6b03c8940d81589ceeb5703f39c32aafde
Reviewed-on: https://chromium-review.googlesource.com/780377
Reviewed-by: Mihai Sardarescu <msarda@chromium.org>
Commit-Queue: Alexander Alekseev <alemate@chromium.org>
Cr-Commit-Position: refs/heads/master@{#518206}
  • Loading branch information
Alexander Alekseev authored and Commit Bot committed Nov 21, 2017
1 parent dc1881f commit ddbeda3
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 172 deletions.
6 changes: 0 additions & 6 deletions google_apis/gaia/gaia_auth_consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ class GaiaAuthConsumer {
virtual void OnGetCheckConnectionInfoSuccess(const std::string& data) {}
virtual void OnGetCheckConnectionInfoError(
const GoogleServiceAuthError& error) {}

virtual void OnListIdpSessionsSuccess(const std::string& login_hint) {}
virtual void OnListIdpSessionsError(const GoogleServiceAuthError& error) {}

virtual void OnGetTokenResponseSuccess(const ClientOAuthResult& result) {}
virtual void OnGetTokenResponseError(const GoogleServiceAuthError& error) {}
};

#endif // GOOGLE_APIS_GAIA_GAIA_AUTH_CONSUMER_H_
137 changes: 3 additions & 134 deletions google_apis/gaia/gaia_auth_fetcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ static bool CookiePartsContains(const std::vector<std::string>& parts,
return false;
}

// From the JSON string |data|, extract the |access_token| and |expires_in_secs|
// both of which must exist. If the |refresh_token| is non-NULL, then it also
// must exist and is extraced; if it's NULL, then no extraction is attempted.
bool ExtractOAuth2TokenPairResponse(const std::string& data,
std::string* refresh_token,
std::string* access_token,
int* expires_in_secs) {
DCHECK(refresh_token);
DCHECK(access_token);
DCHECK(expires_in_secs);

Expand All @@ -62,16 +60,12 @@ bool ExtractOAuth2TokenPairResponse(const std::string& data,
base::DictionaryValue* dict =
static_cast<base::DictionaryValue*>(value.get());

if (!dict->GetStringWithoutPathExpansion("access_token", access_token) ||
if (!dict->GetStringWithoutPathExpansion("refresh_token", refresh_token) ||
!dict->GetStringWithoutPathExpansion("access_token", access_token) ||
!dict->GetIntegerWithoutPathExpansion("expires_in", expires_in_secs)) {
return false;
}

// Refresh token may not be required.
if (refresh_token) {
if (!dict->GetStringWithoutPathExpansion("refresh_token", refresh_token))
return false;
}
return true;
}

Expand All @@ -88,9 +82,6 @@ void GetCookiesFromResponse(const net::HttpResponseHeaders* headers,
}
}

const char kListIdpServiceRequested[] = "list_idp";
const char kGetTokenResponseRequested[] = "get_token";

} // namespace

// static
Expand Down Expand Up @@ -196,7 +187,6 @@ GaiaAuthFetcher::GaiaAuthFetcher(GaiaAuthConsumer* consumer,
logout_gurl_(GaiaUrls::GetInstance()->LogOutURLWithSource(source)),
get_check_connection_info_url_(
GaiaUrls::GetInstance()->GetCheckConnectionInfoURLWithSource(source)),
oauth2_iframe_url_(GaiaUrls::GetInstance()->oauth2_iframe_url()),
deprecated_client_login_to_oauth2_gurl_(
GaiaUrls::GetInstance()->deprecated_client_login_to_oauth2_url()) {}

Expand Down Expand Up @@ -376,43 +366,6 @@ std::string GaiaAuthFetcher::MakeOAuthLoginBody(const std::string& service,
encoded_source.c_str());
}

// static
std::string GaiaAuthFetcher::MakeListIDPSessionsBody(
const std::string& scopes,
const std::string& domain) {
static const char getTokenResponseBodyFormat[] =
"action=listSessions&"
"client_id=%s&"
"origin=%s&"
"scope=%s";
std::string encoded_client_id = net::EscapeUrlEncodedData(
GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true);
return base::StringPrintf(getTokenResponseBodyFormat,
encoded_client_id.c_str(),
domain.c_str(),
scopes.c_str());
}

std::string GaiaAuthFetcher::MakeGetTokenResponseBody(
const std::string& scopes,
const std::string& domain,
const std::string& login_hint) {
static const char getTokenResponseBodyFormat[] =
"action=issueToken&"
"client_id=%s&"
"login_hint=%s&"
"origin=%s&"
"response_type=token&"
"scope=%s";
std::string encoded_client_id = net::EscapeUrlEncodedData(
GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true);
return base::StringPrintf(getTokenResponseBodyFormat,
encoded_client_id.c_str(),
login_hint.c_str(),
domain.c_str(),
scopes.c_str());
}

// static
void GaiaAuthFetcher::ParseClientLoginFailure(const std::string& data,
std::string* error,
Expand Down Expand Up @@ -476,40 +429,6 @@ bool GaiaAuthFetcher::ParseClientLoginToOAuth2Cookie(const std::string& cookie,
return false;
}

// static
bool GaiaAuthFetcher::ParseListIdpSessionsResponse(const std::string& data,
std::string* login_hint) {
DCHECK(login_hint);

std::unique_ptr<base::Value> value = base::JSONReader::Read(data);
if (!value.get() || value->type() != base::Value::Type::DICTIONARY)
return false;

base::DictionaryValue* dict =
static_cast<base::DictionaryValue*>(value.get());

base::ListValue* sessionsList;
if (!dict->GetList("sessions", &sessionsList))
return false;

// Find the first login_hint present in any session.
for (base::ListValue::iterator iter = sessionsList->begin();
iter != sessionsList->end();
iter++) {
base::DictionaryValue* sessionDictionary;
if (!iter->GetAsDictionary(&sessionDictionary))
continue;

if (sessionDictionary->GetString("login_hint", login_hint))
break;
}

if (login_hint->empty())
return false;
return true;
}


void GaiaAuthFetcher::StartRevokeOAuth2Token(const std::string& auth_token) {
DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";

Expand Down Expand Up @@ -936,7 +855,6 @@ void GaiaAuthFetcher::StartGetCheckConnectionInfo() {
kLoadFlagsIgnoreCookies, traffic_annotation);
}


// static
GoogleServiceAuthError GaiaAuthFetcher::GenerateAuthError(
const std::string& data,
Expand Down Expand Up @@ -1139,48 +1057,6 @@ void GaiaAuthFetcher::OnGetCheckConnectionInfoFetched(
}
}

void GaiaAuthFetcher::OnListIdpSessionsFetched(
const std::string& data,
const net::URLRequestStatus& status,
int response_code) {
if (status.is_success() && response_code == net::HTTP_OK) {
VLOG(1) << "ListIdpSessions successful!";
std::string login_hint;
if (ParseListIdpSessionsResponse(data, &login_hint)) {
consumer_->OnListIdpSessionsSuccess(login_hint);
} else {
GoogleServiceAuthError auth_error(
GoogleServiceAuthError::FromUnexpectedServiceResponse(
"List Sessions response didn't contain a login_hint."));
consumer_->OnListIdpSessionsError(auth_error);
}
} else {
consumer_->OnListIdpSessionsError(GenerateAuthError(data, status));
}
}

void GaiaAuthFetcher::OnGetTokenResponseFetched(
const std::string& data,
const net::URLRequestStatus& status,
int response_code) {
std::string access_token;
int expires_in_secs = 0;
bool success = false;
if (status.is_success() && response_code == net::HTTP_OK) {
VLOG(1) << "GetTokenResponse successful!";
success = ExtractOAuth2TokenPairResponse(data, NULL,
&access_token, &expires_in_secs);
}

if (success) {
consumer_->OnGetTokenResponseSuccess(
GaiaAuthConsumer::ClientOAuthResult(std::string(), access_token,
expires_in_secs));
} else {
consumer_->OnGetTokenResponseError(GenerateAuthError(data, status));
}
}

void GaiaAuthFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
fetch_pending_ = false;
// Some of the GAIA requests perform redirects, which results in the final
Expand Down Expand Up @@ -1240,13 +1116,6 @@ void GaiaAuthFetcher::DispatchFetchedRequest(
OnLogOutFetched(data, status, response_code);
} else if (url == get_check_connection_info_url_) {
OnGetCheckConnectionInfoFetched(data, status, response_code);
} else if (url == oauth2_iframe_url_) {
if (requested_service_ == kListIdpServiceRequested)
OnListIdpSessionsFetched(data, status, response_code);
else if (requested_service_ == kGetTokenResponseRequested)
OnGetTokenResponseFetched(data, status, response_code);
else
NOTREACHED();
} else {
NOTREACHED();
}
Expand Down
22 changes: 2 additions & 20 deletions google_apis/gaia/gaia_auth_fetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,6 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate {
const net::URLRequestStatus& status,
int response_code);

void OnListIdpSessionsFetched(const std::string& data,
const net::URLRequestStatus& status,
int response_code);

void OnGetTokenResponseFetched(const std::string& data,
const net::URLRequestStatus& status,
int response_code);

// Tokenize the results of a ClientLogin fetch.
static void ParseClientLoginResponse(const std::string& data,
std::string* sid,
Expand All @@ -362,9 +354,6 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate {
static bool ParseClientLoginToOAuth2Cookie(const std::string& cookie,
std::string* auth_code);

static bool ParseListIdpSessionsResponse(const std::string& data,
std::string* login_hint);

// Is this a special case Gaia error for TwoFactor auth?
static bool IsSecondFactorSuccess(const std::string& alleged_error);

Expand Down Expand Up @@ -398,13 +387,6 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate {
static std::string MakeOAuthLoginBody(const std::string& service,
const std::string& source);

static std::string MakeListIDPSessionsBody(const std::string& scopes,
const std::string& domain);

static std::string MakeGetTokenResponseBody(const std::string& scopes,
const std::string& domain,
const std::string& login_hint);

// From a URLFetcher result, generate an appropriate error.
// From the API documentation, both IssueAuthToken and ClientLogin have
// the same error returns.
Expand All @@ -426,13 +408,13 @@ class GaiaAuthFetcher : public net::URLFetcherDelegate {
const GURL list_accounts_gurl_;
const GURL logout_gurl_;
const GURL get_check_connection_info_url_;
const GURL oauth2_iframe_url_;

// While a fetch is going on:
std::unique_ptr<net::URLFetcher> fetcher_;
GURL deprecated_client_login_to_oauth2_gurl_;
std::string request_body_;
std::string requested_service_;

std::string requested_service_; // Currently tracked for IssueAuthToken only.
bool fetch_pending_ = false;
bool fetch_token_from_auth_code_ = false;

Expand Down
3 changes: 0 additions & 3 deletions google_apis/gaia/gaia_auth_fetcher_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ class MockGaiaConsumer : public GaiaAuthConsumer {
MOCK_METHOD0(OnLogOutSuccess, void());
MOCK_METHOD1(OnLogOutFailure, void(const GoogleServiceAuthError& error));
MOCK_METHOD1(OnGetCheckConnectionInfoSuccess, void(const std::string& data));
MOCK_METHOD1(OnListIdpSessionsSuccess, void(const std::string& data));
MOCK_METHOD1(OnGetTokenResponseSuccess,
void(const GaiaAuthConsumer::ClientOAuthResult& result));
};

#if defined(OS_WIN)
Expand Down
7 changes: 0 additions & 7 deletions google_apis/gaia/gaia_urls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const char kDeprecatedClientLoginToOAuth2UrlSuffix[] =
"o/oauth2/programmatic_auth";
const char kOAuth2AuthUrlSuffix[] = "o/oauth2/auth";
const char kOAuth2RevokeUrlSuffix[] = "o/oauth2/revoke";
const char kOAuth2IFrameUrlSuffix[] = "o/oauth2/iframerpc";

// API calls from www.googleapis.com
const char kOAuth2TokenUrlSuffix[] = "oauth2/v4/token";
Expand Down Expand Up @@ -126,8 +125,6 @@ GaiaUrls::GaiaUrls() {
lso_origin_url_.Resolve(kDeprecatedClientLoginToOAuth2UrlSuffix);
oauth2_auth_url_ = lso_origin_url_.Resolve(kOAuth2AuthUrlSuffix);
oauth2_revoke_url_ = lso_origin_url_.Resolve(kOAuth2RevokeUrlSuffix);
oauth2_iframe_url_ =
lso_origin_url_.Resolve(kOAuth2IFrameUrlSuffix);

// URLs from www.googleapis.com.
oauth2_token_url_ = google_apis_origin_url_.Resolve(kOAuth2TokenUrlSuffix);
Expand Down Expand Up @@ -218,10 +215,6 @@ const GURL& GaiaUrls::oauth_revoke_token_url() const {
return oauth_revoke_token_url_;
}

const GURL& GaiaUrls::oauth2_iframe_url() const {
return oauth2_iframe_url_;
}

const GURL& GaiaUrls::oauth1_login_url() const {
return oauth1_login_url_;
}
Expand Down
2 changes: 0 additions & 2 deletions google_apis/gaia/gaia_urls.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class GaiaUrls {
const GURL& oauth2_issue_token_url() const;
const GURL& oauth2_token_info_url() const;
const GURL& oauth2_revoke_url() const;
const GURL& oauth2_iframe_url() const;

const GURL& gaia_login_form_realm() const;

Expand Down Expand Up @@ -100,7 +99,6 @@ class GaiaUrls {
GURL oauth2_issue_token_url_;
GURL oauth2_token_info_url_;
GURL oauth2_revoke_url_;
GURL oauth2_iframe_url_;

GURL gaia_login_form_realm_;

Expand Down

0 comments on commit ddbeda3

Please sign in to comment.