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

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

Issue 11649055: OAuth2 sign-in flow for ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 "service=%s&" 73 "service=%s&"
74 "logintoken=%s&" 74 "logintoken=%s&"
75 "logincaptcha=%s"; 75 "logincaptcha=%s";
76 // static 76 // static
77 const char GaiaAuthFetcher::kIssueAuthTokenFormat[] = 77 const char GaiaAuthFetcher::kIssueAuthTokenFormat[] =
78 "SID=%s&" 78 "SID=%s&"
79 "LSID=%s&" 79 "LSID=%s&"
80 "service=%s&" 80 "service=%s&"
81 "Session=%s"; 81 "Session=%s";
82 // static 82 // static
83 const char GaiaAuthFetcher::kIssueAuthTokenFormatForOAuth2[] =
84 "service=%s&"
85 "Session=%s";
86 // static
83 const char GaiaAuthFetcher::kClientLoginToOAuth2BodyFormat[] = 87 const char GaiaAuthFetcher::kClientLoginToOAuth2BodyFormat[] =
84 "scope=%s&client_id=%s"; 88 "scope=%s&client_id=%s";
85 // static 89 // static
86 const char GaiaAuthFetcher::kOAuth2CodeToTokenPairBodyFormat[] = 90 const char GaiaAuthFetcher::kOAuth2CodeToTokenPairBodyFormat[] =
87 "scope=%s&" 91 "scope=%s&"
88 "grant_type=authorization_code&" 92 "grant_type=authorization_code&"
89 "client_id=%s&" 93 "client_id=%s&"
90 "client_secret=%s&" 94 "client_secret=%s&"
91 "code=%s"; 95 "code=%s";
92 // static 96 // static
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 153
150 // static 154 // static
151 const char GaiaAuthFetcher::kSecondFactor[] = "Info=InvalidSecondFactor"; 155 const char GaiaAuthFetcher::kSecondFactor[] = "Info=InvalidSecondFactor";
152 156
153 // static 157 // static
154 const char GaiaAuthFetcher::kAuthHeaderFormat[] = 158 const char GaiaAuthFetcher::kAuthHeaderFormat[] =
155 "Authorization: GoogleLogin auth=%s"; 159 "Authorization: GoogleLogin auth=%s";
156 // static 160 // static
157 const char GaiaAuthFetcher::kOAuthHeaderFormat[] = "Authorization: OAuth %s"; 161 const char GaiaAuthFetcher::kOAuthHeaderFormat[] = "Authorization: OAuth %s";
158 // static 162 // static
163 const char GaiaAuthFetcher::kOAuth2BearerHeaderFormat[] =
164 "Authorization: Bearer %s";
165 // static
159 const char GaiaAuthFetcher::kClientLoginToOAuth2CookiePartSecure[] = "Secure"; 166 const char GaiaAuthFetcher::kClientLoginToOAuth2CookiePartSecure[] = "Secure";
160 // static 167 // static
161 const char GaiaAuthFetcher::kClientLoginToOAuth2CookiePartHttpOnly[] = 168 const char GaiaAuthFetcher::kClientLoginToOAuth2CookiePartHttpOnly[] =
162 "HttpOnly"; 169 "HttpOnly";
163 // static 170 // static
164 const char GaiaAuthFetcher::kClientLoginToOAuth2CookiePartCodePrefix[] = 171 const char GaiaAuthFetcher::kClientLoginToOAuth2CookiePartCodePrefix[] =
165 "oauth_code="; 172 "oauth_code=";
166 // static 173 // static
167 const int GaiaAuthFetcher::kClientLoginToOAuth2CookiePartCodePrefixLength = 174 const int GaiaAuthFetcher::kClientLoginToOAuth2CookiePartCodePrefixLength =
168 arraysize(GaiaAuthFetcher::kClientLoginToOAuth2CookiePartCodePrefix) - 1; 175 arraysize(GaiaAuthFetcher::kClientLoginToOAuth2CookiePartCodePrefix) - 1;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 session = false; 291 session = false;
285 292
286 return base::StringPrintf(kIssueAuthTokenFormat, 293 return base::StringPrintf(kIssueAuthTokenFormat,
287 encoded_sid.c_str(), 294 encoded_sid.c_str(),
288 encoded_lsid.c_str(), 295 encoded_lsid.c_str(),
289 service, 296 service,
290 session ? "true" : "false"); 297 session ? "true" : "false");
291 } 298 }
292 299
293 // static 300 // static
301 std::string GaiaAuthFetcher::MakeIssueAuthTokenBodyForOAuth2(
302 const char* const service) {
303 // All tokens should be session tokens except the gaia auth token.
304 bool session = true;
305 if (!strcmp(service, GaiaConstants::kGaiaService))
306 session = false;
307
308 return base::StringPrintf(kIssueAuthTokenFormatForOAuth2,
309 service,
310 session ? "true" : "false");
311 }
312
313 // static
294 std::string GaiaAuthFetcher::MakeGetAuthCodeBody() { 314 std::string GaiaAuthFetcher::MakeGetAuthCodeBody() {
295 std::string encoded_scope = net::EscapeUrlEncodedData( 315 std::string encoded_scope = net::EscapeUrlEncodedData(
296 GaiaUrls::GetInstance()->oauth1_login_scope(), true); 316 GaiaUrls::GetInstance()->oauth1_login_scope(), true);
297 std::string encoded_client_id = net::EscapeUrlEncodedData( 317 std::string encoded_client_id = net::EscapeUrlEncodedData(
298 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true); 318 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true);
299 return StringPrintf(kClientLoginToOAuth2BodyFormat, 319 return StringPrintf(kClientLoginToOAuth2BodyFormat,
300 encoded_scope.c_str(), 320 encoded_scope.c_str(),
301 encoded_client_id.c_str()); 321 encoded_client_id.c_str());
302 } 322 }
303 323
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 fetcher_.reset(CreateGaiaFetcher(getter_, 629 fetcher_.reset(CreateGaiaFetcher(getter_,
610 request_body_, 630 request_body_,
611 "", 631 "",
612 issue_auth_token_gurl_, 632 issue_auth_token_gurl_,
613 kLoadFlagsIgnoreCookies, 633 kLoadFlagsIgnoreCookies,
614 this)); 634 this));
615 fetch_pending_ = true; 635 fetch_pending_ = true;
616 fetcher_->Start(); 636 fetcher_->Start();
617 } 637 }
618 638
639 void GaiaAuthFetcher::StartIssueAuthTokenForOAuth2(
640 const std::string& oauth2_access_token,
641 const char* const service) {
642 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
643
644 DVLOG(1) << "Starting IssueAuthToken for: " << service;
645 requested_service_ = service;
646 request_body_ = MakeIssueAuthTokenBodyForOAuth2(service);
647 std::string authentication_header =
648 base::StringPrintf(kOAuth2BearerHeaderFormat,
649 oauth2_access_token.c_str());
650 fetcher_.reset(CreateGaiaFetcher(getter_,
651 request_body_,
652 authentication_header,
653 issue_auth_token_gurl_,
654 kLoadFlagsIgnoreCookies,
655 this));
656 fetch_pending_ = true;
657 fetcher_->Start();
658 }
659
619 void GaiaAuthFetcher::StartLsoForOAuthLoginTokenExchange( 660 void GaiaAuthFetcher::StartLsoForOAuthLoginTokenExchange(
620 const std::string& auth_token) { 661 const std::string& auth_token) {
621 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 662 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
622 663
623 DVLOG(1) << "Starting OAuth login token exchange with auth_token"; 664 DVLOG(1) << "Starting OAuth login token exchange with auth_token";
624 request_body_ = MakeGetAuthCodeBody(); 665 request_body_ = MakeGetAuthCodeBody();
625 client_login_to_oauth2_gurl_ = 666 client_login_to_oauth2_gurl_ =
626 GURL(GaiaUrls::GetInstance()->client_login_to_oauth2_url()); 667 GURL(GaiaUrls::GetInstance()->client_login_to_oauth2_url());
627 668
628 fetcher_.reset(CreateGaiaFetcher(getter_, 669 fetcher_.reset(CreateGaiaFetcher(getter_,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 fetch_pending_ = true; 804 fetch_pending_ = true;
764 fetcher_->Start(); 805 fetcher_->Start();
765 } 806 }
766 807
767 void GaiaAuthFetcher::StartOAuthLogin(const std::string& access_token, 808 void GaiaAuthFetcher::StartOAuthLogin(const std::string& access_token,
768 const std::string& service) { 809 const std::string& service) {
769 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 810 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
770 811
771 request_body_ = MakeOAuthLoginBody(service, source_); 812 request_body_ = MakeOAuthLoginBody(service, source_);
772 std::string authentication_header = 813 std::string authentication_header =
773 base::StringPrintf("Authorization: Bearer %s", access_token.c_str()); 814 base::StringPrintf(kOAuth2BearerHeaderFormat, access_token.c_str());
774 fetcher_.reset(CreateGaiaFetcher(getter_, 815 fetcher_.reset(CreateGaiaFetcher(getter_,
775 request_body_, 816 request_body_,
776 authentication_header, 817 authentication_header,
777 oauth_login_gurl_, 818 oauth_login_gurl_,
778 kLoadFlagsIgnoreCookies, 819 kLoadFlagsIgnoreCookies,
779 this)); 820 this));
780 fetch_pending_ = true; 821 fetch_pending_ = true;
781 fetcher_->Start(); 822 fetcher_->Start();
782 } 823 }
783 824
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 NOTREACHED(); 1138 NOTREACHED();
1098 } 1139 }
1099 } 1140 }
1100 1141
1101 // static 1142 // static
1102 bool GaiaAuthFetcher::IsSecondFactorSuccess( 1143 bool GaiaAuthFetcher::IsSecondFactorSuccess(
1103 const std::string& alleged_error) { 1144 const std::string& alleged_error) {
1104 return alleged_error.find(kSecondFactor) != 1145 return alleged_error.find(kSecondFactor) !=
1105 std::string::npos; 1146 std::string::npos;
1106 } 1147 }
OLDNEW
« chrome/browser/chromeos/login/user_manager_impl.cc ('K') | « google_apis/gaia/gaia_auth_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698