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

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

Issue 473153002: Inline sign in extracts gaia id from HTTP header and seeds account tracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix error message Created 6 years, 2 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/fake_gaia.h" 5 #include "google_apis/gaia/fake_gaia.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 const char kTestAuthCode[] = "fake-auth-code"; 44 const char kTestAuthCode[] = "fake-auth-code";
45 const char kTestGaiaUberToken[] = "fake-uber-token"; 45 const char kTestGaiaUberToken[] = "fake-uber-token";
46 const char kTestAuthLoginAccessToken[] = "fake-access-token"; 46 const char kTestAuthLoginAccessToken[] = "fake-access-token";
47 const char kTestRefreshToken[] = "fake-refresh-token"; 47 const char kTestRefreshToken[] = "fake-refresh-token";
48 const char kTestSessionSIDCookie[] = "fake-session-SID-cookie"; 48 const char kTestSessionSIDCookie[] = "fake-session-SID-cookie";
49 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie"; 49 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie";
50 const char kTestOAuthLoginSID[] = "fake-oauth-SID-cookie"; 50 const char kTestOAuthLoginSID[] = "fake-oauth-SID-cookie";
51 const char kTestOAuthLoginLSID[] = "fake-oauth-LSID-cookie"; 51 const char kTestOAuthLoginLSID[] = "fake-oauth-LSID-cookie";
52 const char kTestOAuthLoginAuthCode[] = "fake-oauth-auth-code"; 52 const char kTestOAuthLoginAuthCode[] = "fake-oauth-auth-code";
53 53
54 const char kDefaultGaiaId[] ="12345";
55
54 const base::FilePath::CharType kServiceLogin[] = 56 const base::FilePath::CharType kServiceLogin[] =
55 FILE_PATH_LITERAL("google_apis/test/service_login.html"); 57 FILE_PATH_LITERAL("google_apis/test/service_login.html");
56 58
57 // OAuth2 Authentication header value prefix. 59 // OAuth2 Authentication header value prefix.
58 const char kAuthHeaderBearer[] = "Bearer "; 60 const char kAuthHeaderBearer[] = "Bearer ";
59 const char kAuthHeaderOAuth[] = "OAuth "; 61 const char kAuthHeaderOAuth[] = "OAuth ";
60 62
61 const char kListAccountsResponseFormat[] = 63 const char kListAccountsResponseFormat[] =
62 "[\"gaia.l.a.r\",[[\"gaia.l.a\",1,\"\",\"%s\",\"\",1,1,0]]]"; 64 "[\"gaia.l.a.r\",[[\"gaia.l.a\",1,\"\",\"%s\",\"\",1,1,0]]]";
63 65
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 params.session_lsid_cookie = kTestSessionLSIDCookie; 158 params.session_lsid_cookie = kTestSessionLSIDCookie;
157 params.email = email; 159 params.email = email;
158 SetMergeSessionParams(params); 160 SetMergeSessionParams(params);
159 } 161 }
160 162
161 void FakeGaia::SetMergeSessionParams( 163 void FakeGaia::SetMergeSessionParams(
162 const MergeSessionParams& params) { 164 const MergeSessionParams& params) {
163 merge_session_params_ = params; 165 merge_session_params_ = params;
164 } 166 }
165 167
168 void FakeGaia::MapEmailToGaiaId(const std::string& email,
169 const std::string& gaia_id) {
170 DCHECK(!email.empty());
171 DCHECK(!gaia_id.empty());
172 email_to_gaia_id_map_[email] = gaia_id;
173 }
174
175 std::string FakeGaia::GetGaiaIdOfEmail(const std::string& email) {
176 DCHECK(!email.empty());
177 std::string gaia_id = email_to_gaia_id_map_[email];
178 return gaia_id.empty() ? std::string(kDefaultGaiaId) : gaia_id;
179 }
180
166 void FakeGaia::Initialize() { 181 void FakeGaia::Initialize() {
167 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 182 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
168 // Handles /MergeSession GAIA call. 183 // Handles /MergeSession GAIA call.
169 REGISTER_RESPONSE_HANDLER( 184 REGISTER_RESPONSE_HANDLER(
170 gaia_urls->merge_session_url(), HandleMergeSession); 185 gaia_urls->merge_session_url(), HandleMergeSession);
171 186
172 // Handles /o/oauth2/programmatic_auth GAIA call. 187 // Handles /o/oauth2/programmatic_auth GAIA call.
173 REGISTER_RESPONSE_HANDLER( 188 REGISTER_RESPONSE_HANDLER(
174 gaia_urls->client_login_to_oauth2_url(), HandleProgramaticAuth); 189 gaia_urls->client_login_to_oauth2_url(), HandleProgramaticAuth);
175 190
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 423
409 void FakeGaia::HandleServiceLoginAuth(const HttpRequest& request, 424 void FakeGaia::HandleServiceLoginAuth(const HttpRequest& request,
410 BasicHttpResponse* http_response) { 425 BasicHttpResponse* http_response) {
411 std::string continue_url = 426 std::string continue_url =
412 GaiaUrls::GetInstance()->service_login_url().spec(); 427 GaiaUrls::GetInstance()->service_login_url().spec();
413 GetQueryParameter(request.content, "continue", &continue_url); 428 GetQueryParameter(request.content, "continue", &continue_url);
414 429
415 std::string redirect_url = continue_url; 430 std::string redirect_url = continue_url;
416 431
417 std::string email; 432 std::string email;
418 if (GetQueryParameter(request.content, "Email", &email) && 433 const bool is_saml =
419 saml_account_idp_map_.find(email) != saml_account_idp_map_.end()) { 434 GetQueryParameter(request.content, "Email", &email) &&
435 saml_account_idp_map_.find(email) != saml_account_idp_map_.end();
436
437 if (is_saml) {
420 GURL url(saml_account_idp_map_[email]); 438 GURL url(saml_account_idp_map_[email]);
421 url = net::AppendQueryParameter(url, "SAMLRequest", "fake_request"); 439 url = net::AppendQueryParameter(url, "SAMLRequest", "fake_request");
422 url = net::AppendQueryParameter(url, "RelayState", continue_url); 440 url = net::AppendQueryParameter(url, "RelayState", continue_url);
423 redirect_url = url.spec(); 441 redirect_url = url.spec();
424 http_response->AddCustomHeader("Google-Accounts-SAML", "Start"); 442 http_response->AddCustomHeader("Google-Accounts-SAML", "Start");
425 } else if (!merge_session_params_.auth_sid_cookie.empty() && 443 } else if (!merge_session_params_.auth_sid_cookie.empty() &&
426 !merge_session_params_.auth_lsid_cookie.empty()) { 444 !merge_session_params_.auth_lsid_cookie.empty()) {
427 SetCookies(http_response, 445 SetCookies(http_response,
428 merge_session_params_.auth_sid_cookie, 446 merge_session_params_.auth_sid_cookie,
429 merge_session_params_.auth_lsid_cookie); 447 merge_session_params_.auth_lsid_cookie);
430 } 448 }
431 449
432 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); 450 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT);
433 http_response->AddCustomHeader("Location", redirect_url); 451 http_response->AddCustomHeader("Location", redirect_url);
434 http_response->AddCustomHeader("google-accounts-signin", 452
435 base::StringPrintf("email=\"%s\", sessionindex=0", email.c_str())); 453 // SAML sign-ins complete in HandleSSO().
454 if (!is_saml) {
bartfab (slow) 2014/10/21 14:47:47 Nit: You could simplify this by rversing the condi
Roger Tawa OOO till Jul 10th 2014/10/21 19:15:31 Done.
455 DCHECK(!email.empty());
456 http_response->AddCustomHeader("google-accounts-signin",
bartfab (slow) 2014/10/21 14:47:47 Nit: This should be extracted into a helper method
Roger Tawa OOO till Jul 10th 2014/10/21 19:15:31 Done.
457 base::StringPrintf(
458 "email=\"%s\", obfuscatedid=\"%s\", sessionindex=0",
459 email.c_str(), GetGaiaIdOfEmail(email).c_str()));
460 }
436 } 461 }
437 462
438 void FakeGaia::HandleSSO(const HttpRequest& request, 463 void FakeGaia::HandleSSO(const HttpRequest& request,
439 BasicHttpResponse* http_response) { 464 BasicHttpResponse* http_response) {
440 if (!merge_session_params_.auth_sid_cookie.empty() && 465 if (!merge_session_params_.auth_sid_cookie.empty() &&
441 !merge_session_params_.auth_lsid_cookie.empty()) { 466 !merge_session_params_.auth_lsid_cookie.empty()) {
442 SetCookies(http_response, 467 SetCookies(http_response,
443 merge_session_params_.auth_sid_cookie, 468 merge_session_params_.auth_sid_cookie,
444 merge_session_params_.auth_lsid_cookie); 469 merge_session_params_.auth_lsid_cookie);
445 } 470 }
446 std::string relay_state; 471 std::string relay_state;
447 GetQueryParameter(request.content, "RelayState", &relay_state); 472 GetQueryParameter(request.content, "RelayState", &relay_state);
448 std::string redirect_url = relay_state; 473 std::string redirect_url = relay_state;
449 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); 474 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT);
450 http_response->AddCustomHeader("Location", redirect_url); 475 http_response->AddCustomHeader("Location", redirect_url);
451 http_response->AddCustomHeader("Google-Accounts-SAML", "End"); 476 http_response->AddCustomHeader("Google-Accounts-SAML", "End");
477
478 if (!merge_session_params_.email.empty()) {
479 http_response->AddCustomHeader("google-accounts-signin",
480 base::StringPrintf(
481 "email=\"%s\", obfuscatedid=\"%s\", sessionindex=0",
482 merge_session_params_.email.c_str(),
483 GetGaiaIdOfEmail(merge_session_params_.email).c_str()));
484 }
452 } 485 }
453 486
454 void FakeGaia::HandleAuthToken(const HttpRequest& request, 487 void FakeGaia::HandleAuthToken(const HttpRequest& request,
455 BasicHttpResponse* http_response) { 488 BasicHttpResponse* http_response) {
456 std::string scope; 489 std::string scope;
457 GetQueryParameter(request.content, "scope", &scope); 490 GetQueryParameter(request.content, "scope", &scope);
458 491
459 std::string grant_type; 492 std::string grant_type;
460 if (!GetQueryParameter(request.content, "grant_type", &grant_type)) { 493 if (!GetQueryParameter(request.content, "grant_type", &grant_type)) {
461 http_response->set_code(net::HTTP_BAD_REQUEST); 494 http_response->set_code(net::HTTP_BAD_REQUEST);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 } 606 }
574 607
575 void FakeGaia::HandleGetUserInfo(const HttpRequest& request, 608 void FakeGaia::HandleGetUserInfo(const HttpRequest& request,
576 BasicHttpResponse* http_response) { 609 BasicHttpResponse* http_response) {
577 http_response->set_content(base::StringPrintf( 610 http_response->set_content(base::StringPrintf(
578 "email=%s\ndisplayEmail=%s", 611 "email=%s\ndisplayEmail=%s",
579 merge_session_params_.email.c_str(), 612 merge_session_params_.email.c_str(),
580 merge_session_params_.email.c_str())); 613 merge_session_params_.email.c_str()));
581 http_response->set_code(net::HTTP_OK); 614 http_response->set_code(net::HTTP_OK);
582 } 615 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698