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

Side by Side Diff: google_apis/gaia/gaia_auth_fetcher.cc

Issue 13599003: revoke unused OAuth2 tokens on signout and re-signin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 7 years, 8 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 unified diff | Download patch
« no previous file with comments | « google_apis/gaia/gaia_auth_fetcher.h ('k') | google_apis/gaia/gaia_urls.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "google_apis/gaia/gaia_auth_fetcher.h" 5 #include "google_apis/gaia/gaia_auth_fetcher.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 const char GaiaAuthFetcher::kClientLoginToOAuth2BodyFormat[] = 84 const char GaiaAuthFetcher::kClientLoginToOAuth2BodyFormat[] =
85 "scope=%s&client_id=%s"; 85 "scope=%s&client_id=%s";
86 // static 86 // static
87 const char GaiaAuthFetcher::kOAuth2CodeToTokenPairBodyFormat[] = 87 const char GaiaAuthFetcher::kOAuth2CodeToTokenPairBodyFormat[] =
88 "scope=%s&" 88 "scope=%s&"
89 "grant_type=authorization_code&" 89 "grant_type=authorization_code&"
90 "client_id=%s&" 90 "client_id=%s&"
91 "client_secret=%s&" 91 "client_secret=%s&"
92 "code=%s"; 92 "code=%s";
93 // static 93 // static
94 const char GaiaAuthFetcher::kOAuth2RevokeTokenBodyFormat[] =
95 "token=%s";
96 // static
94 const char GaiaAuthFetcher::kGetUserInfoFormat[] = 97 const char GaiaAuthFetcher::kGetUserInfoFormat[] =
95 "LSID=%s"; 98 "LSID=%s";
96 // static 99 // static
97 const char GaiaAuthFetcher::kMergeSessionFormat[] = 100 const char GaiaAuthFetcher::kMergeSessionFormat[] =
98 "uberauth=%s&" 101 "uberauth=%s&"
99 "continue=%s&" 102 "continue=%s&"
100 "source=%s"; 103 "source=%s";
101 // static 104 // static
102 const char GaiaAuthFetcher::kUberAuthTokenURLFormat[] = 105 const char GaiaAuthFetcher::kUberAuthTokenURLFormat[] =
103 "%s?source=%s&" 106 "%s?source=%s&"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 176
174 GaiaAuthFetcher::GaiaAuthFetcher(GaiaAuthConsumer* consumer, 177 GaiaAuthFetcher::GaiaAuthFetcher(GaiaAuthConsumer* consumer,
175 const std::string& source, 178 const std::string& source,
176 net::URLRequestContextGetter* getter) 179 net::URLRequestContextGetter* getter)
177 : consumer_(consumer), 180 : consumer_(consumer),
178 getter_(getter), 181 getter_(getter),
179 source_(source), 182 source_(source),
180 client_login_gurl_(GaiaUrls::GetInstance()->client_login_url()), 183 client_login_gurl_(GaiaUrls::GetInstance()->client_login_url()),
181 issue_auth_token_gurl_(GaiaUrls::GetInstance()->issue_auth_token_url()), 184 issue_auth_token_gurl_(GaiaUrls::GetInstance()->issue_auth_token_url()),
182 oauth2_token_gurl_(GaiaUrls::GetInstance()->oauth2_token_url()), 185 oauth2_token_gurl_(GaiaUrls::GetInstance()->oauth2_token_url()),
186 oauth2_revoke_gurl_(GaiaUrls::GetInstance()->oauth2_revoke_url()),
183 get_user_info_gurl_(GaiaUrls::GetInstance()->get_user_info_url()), 187 get_user_info_gurl_(GaiaUrls::GetInstance()->get_user_info_url()),
184 merge_session_gurl_(GaiaUrls::GetInstance()->merge_session_url()), 188 merge_session_gurl_(GaiaUrls::GetInstance()->merge_session_url()),
185 uberauth_token_gurl_(base::StringPrintf(kUberAuthTokenURLFormat, 189 uberauth_token_gurl_(base::StringPrintf(kUberAuthTokenURLFormat,
186 GaiaUrls::GetInstance()->oauth1_login_url().c_str(), source.c_str())), 190 GaiaUrls::GetInstance()->oauth1_login_url().c_str(), source.c_str())),
187 client_oauth_gurl_(GaiaUrls::GetInstance()->client_oauth_url()), 191 client_oauth_gurl_(GaiaUrls::GetInstance()->client_oauth_url()),
188 oauth_login_gurl_(GaiaUrls::GetInstance()->oauth1_login_url()), 192 oauth_login_gurl_(GaiaUrls::GetInstance()->oauth1_login_url()),
189 client_login_to_oauth2_gurl_( 193 client_login_to_oauth2_gurl_(
190 GaiaUrls::GetInstance()->client_login_to_oauth2_url()), 194 GaiaUrls::GetInstance()->client_login_to_oauth2_url()),
191 fetch_pending_(false) {} 195 fetch_pending_(false) {}
192 196
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), true); 326 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), true);
323 std::string encoded_auth_code = net::EscapeUrlEncodedData(auth_code, true); 327 std::string encoded_auth_code = net::EscapeUrlEncodedData(auth_code, true);
324 return base::StringPrintf(kOAuth2CodeToTokenPairBodyFormat, 328 return base::StringPrintf(kOAuth2CodeToTokenPairBodyFormat,
325 encoded_scope.c_str(), 329 encoded_scope.c_str(),
326 encoded_client_id.c_str(), 330 encoded_client_id.c_str(),
327 encoded_client_secret.c_str(), 331 encoded_client_secret.c_str(),
328 encoded_auth_code.c_str()); 332 encoded_auth_code.c_str());
329 } 333 }
330 334
331 // static 335 // static
336 std::string GaiaAuthFetcher::MakeRevokeTokenBody(
337 const std::string& auth_token) {
338 return base::StringPrintf(kOAuth2RevokeTokenBodyFormat, auth_token.c_str());
339 }
340
341 // static
332 std::string GaiaAuthFetcher::MakeGetUserInfoBody(const std::string& lsid) { 342 std::string GaiaAuthFetcher::MakeGetUserInfoBody(const std::string& lsid) {
333 std::string encoded_lsid = net::EscapeUrlEncodedData(lsid, true); 343 std::string encoded_lsid = net::EscapeUrlEncodedData(lsid, true);
334 return base::StringPrintf(kGetUserInfoFormat, encoded_lsid.c_str()); 344 return base::StringPrintf(kGetUserInfoFormat, encoded_lsid.c_str());
335 } 345 }
336 346
337 // static 347 // static
338 std::string GaiaAuthFetcher::MakeMergeSessionBody( 348 std::string GaiaAuthFetcher::MakeMergeSessionBody(
339 const std::string& auth_token, 349 const std::string& auth_token,
340 const std::string& continue_url, 350 const std::string& continue_url,
341 const std::string& source) { 351 const std::string& source) {
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 fetcher_.reset(CreateGaiaFetcher(getter_, 655 fetcher_.reset(CreateGaiaFetcher(getter_,
646 request_body_, 656 request_body_,
647 MakeGetAuthCodeHeader(auth_token), 657 MakeGetAuthCodeHeader(auth_token),
648 client_login_to_oauth2_gurl_, 658 client_login_to_oauth2_gurl_,
649 kLoadFlagsIgnoreCookies, 659 kLoadFlagsIgnoreCookies,
650 this)); 660 this));
651 fetch_pending_ = true; 661 fetch_pending_ = true;
652 fetcher_->Start(); 662 fetcher_->Start();
653 } 663 }
654 664
665 void GaiaAuthFetcher::StartRevokeOAuth2Token(const std::string& auth_token) {
666 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
667
668 DVLOG(1) << "Starting OAuth2 token revocation";
669 request_body_ = MakeRevokeTokenBody(auth_token);
670 fetcher_.reset(CreateGaiaFetcher(getter_,
671 request_body_,
672 "",
673 oauth2_revoke_gurl_,
674 kLoadFlagsIgnoreCookies,
675 this));
676 fetch_pending_ = true;
677 fetcher_->Start();
678 }
679
655 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange( 680 void GaiaAuthFetcher::StartCookieForOAuthLoginTokenExchange(
656 const std::string& session_index) { 681 const std::string& session_index) {
657 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 682 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
658 683
659 DVLOG(1) << "Starting OAuth login token fetch with cookie jar"; 684 DVLOG(1) << "Starting OAuth login token fetch with cookie jar";
660 request_body_ = MakeGetAuthCodeBody(); 685 request_body_ = MakeGetAuthCodeBody();
661 686
662 std::string url = GaiaUrls::GetInstance()->client_login_to_oauth2_url(); 687 std::string url = GaiaUrls::GetInstance()->client_login_to_oauth2_url();
663 if (!session_index.empty()) 688 if (!session_index.empty())
664 url += "?authuser=" + session_index; 689 url += "?authuser=" + session_index;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 1009
985 if (success) { 1010 if (success) {
986 consumer_->OnClientOAuthSuccess( 1011 consumer_->OnClientOAuthSuccess(
987 GaiaAuthConsumer::ClientOAuthResult(refresh_token, access_token, 1012 GaiaAuthConsumer::ClientOAuthResult(refresh_token, access_token,
988 expires_in_secs)); 1013 expires_in_secs));
989 } else { 1014 } else {
990 consumer_->OnClientOAuthFailure(GenerateAuthError(data, status)); 1015 consumer_->OnClientOAuthFailure(GenerateAuthError(data, status));
991 } 1016 }
992 } 1017 }
993 1018
1019 void GaiaAuthFetcher::OnOAuth2RevokeTokenFetched(
1020 const std::string& data,
1021 const net::URLRequestStatus& status,
1022 int response_code) {
1023 consumer_->OnOAuth2RevokeTokenCompleted();
1024 }
1025
994 void GaiaAuthFetcher::OnGetUserInfoFetched( 1026 void GaiaAuthFetcher::OnGetUserInfoFetched(
995 const std::string& data, 1027 const std::string& data,
996 const net::URLRequestStatus& status, 1028 const net::URLRequestStatus& status,
997 int response_code) { 1029 int response_code) {
998 if (status.is_success() && response_code == net::HTTP_OK) { 1030 if (status.is_success() && response_code == net::HTTP_OK) {
999 std::vector<std::pair<std::string, std::string> > tokens; 1031 std::vector<std::pair<std::string, std::string> > tokens;
1000 UserInfoMap matches; 1032 UserInfoMap matches;
1001 base::SplitStringIntoKeyValuePairs(data, '=', '\n', &tokens); 1033 base::SplitStringIntoKeyValuePairs(data, '=', '\n', &tokens);
1002 std::vector<std::pair<std::string, std::string> >::iterator i; 1034 std::vector<std::pair<std::string, std::string> >::iterator i;
1003 for (i = tokens.begin(); i != tokens.end(); ++i) { 1035 for (i = tokens.begin(); i != tokens.end(); ++i) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 } else if (url == get_user_info_gurl_) { 1144 } else if (url == get_user_info_gurl_) {
1113 OnGetUserInfoFetched(data, status, response_code); 1145 OnGetUserInfoFetched(data, status, response_code);
1114 } else if (url == merge_session_gurl_) { 1146 } else if (url == merge_session_gurl_) {
1115 OnMergeSessionFetched(data, status, response_code); 1147 OnMergeSessionFetched(data, status, response_code);
1116 } else if (url == uberauth_token_gurl_) { 1148 } else if (url == uberauth_token_gurl_) {
1117 OnUberAuthTokenFetch(data, status, response_code); 1149 OnUberAuthTokenFetch(data, status, response_code);
1118 } else if (url == client_oauth_gurl_) { 1150 } else if (url == client_oauth_gurl_) {
1119 OnClientOAuthFetched(data, status, response_code); 1151 OnClientOAuthFetched(data, status, response_code);
1120 } else if (url == oauth_login_gurl_) { 1152 } else if (url == oauth_login_gurl_) {
1121 OnOAuthLoginFetched(data, status, response_code); 1153 OnOAuthLoginFetched(data, status, response_code);
1154 } else if (url == oauth2_revoke_gurl_) {
1155 OnOAuth2RevokeTokenFetched(data, status, response_code);
1122 } else { 1156 } else {
1123 NOTREACHED(); 1157 NOTREACHED();
1124 } 1158 }
1125 } 1159 }
1126 1160
1127 // static 1161 // static
1128 bool GaiaAuthFetcher::IsSecondFactorSuccess( 1162 bool GaiaAuthFetcher::IsSecondFactorSuccess(
1129 const std::string& alleged_error) { 1163 const std::string& alleged_error) {
1130 return alleged_error.find(kSecondFactor) != 1164 return alleged_error.find(kSecondFactor) !=
1131 std::string::npos; 1165 std::string::npos;
1132 } 1166 }
OLDNEW
« no previous file with comments | « google_apis/gaia/gaia_auth_fetcher.h ('k') | google_apis/gaia/gaia_urls.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698