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

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

Issue 1004753004: cros: Port SAML support to webview sign-in. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: handle loadabort to fix test Created 5 years, 9 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/fake_gaia.h ('k') | no next file » | 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) 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 : expires_in(3600) {} 126 : expires_in(3600) {}
127 127
128 FakeGaia::AccessTokenInfo::~AccessTokenInfo() {} 128 FakeGaia::AccessTokenInfo::~AccessTokenInfo() {}
129 129
130 FakeGaia::MergeSessionParams::MergeSessionParams() { 130 FakeGaia::MergeSessionParams::MergeSessionParams() {
131 } 131 }
132 132
133 FakeGaia::MergeSessionParams::~MergeSessionParams() { 133 FakeGaia::MergeSessionParams::~MergeSessionParams() {
134 } 134 }
135 135
136 FakeGaia::FakeGaia() { 136 FakeGaia::FakeGaia() : issue_oauth_code_cookie_(false) {
137 base::FilePath source_root_dir; 137 base::FilePath source_root_dir;
138 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir); 138 PathService::Get(base::DIR_SOURCE_ROOT, &source_root_dir);
139 CHECK(base::ReadFileToString( 139 CHECK(base::ReadFileToString(
140 source_root_dir.Append(base::FilePath(kServiceLogin)), 140 source_root_dir.Append(base::FilePath(kServiceLogin)),
141 &service_login_response_)); 141 &service_login_response_));
142 } 142 }
143 143
144 FakeGaia::~FakeGaia() {} 144 FakeGaia::~FakeGaia() {}
145 145
146 void FakeGaia::SetFakeMergeSessionParams( 146 void FakeGaia::SetFakeMergeSessionParams(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 void FakeGaia::AddGoogleAccountsSigninHeader( 182 void FakeGaia::AddGoogleAccountsSigninHeader(
183 net::test_server::BasicHttpResponse* http_response, 183 net::test_server::BasicHttpResponse* http_response,
184 const std::string& email) const { 184 const std::string& email) const {
185 DCHECK(!email.empty()); 185 DCHECK(!email.empty());
186 http_response->AddCustomHeader("google-accounts-signin", 186 http_response->AddCustomHeader("google-accounts-signin",
187 base::StringPrintf( 187 base::StringPrintf(
188 "email=\"%s\", obfuscatedid=\"%s\", sessionindex=0", 188 "email=\"%s\", obfuscatedid=\"%s\", sessionindex=0",
189 email.c_str(), GetGaiaIdOfEmail(email).c_str())); 189 email.c_str(), GetGaiaIdOfEmail(email).c_str()));
190 } 190 }
191 191
192 void FakeGaia::SetOAuthCodeCookie(
193 net::test_server::BasicHttpResponse* http_response) const {
194 http_response->AddCustomHeader(
195 "Set-Cookie",
196 base::StringPrintf(
197 "oauth_code=%s; Path=/o/GetOAuth2Token; Secure; HttpOnly;",
198 merge_session_params_.auth_code.c_str()));
199 }
200
192 void FakeGaia::Initialize() { 201 void FakeGaia::Initialize() {
193 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 202 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
194 // Handles /MergeSession GAIA call. 203 // Handles /MergeSession GAIA call.
195 REGISTER_RESPONSE_HANDLER( 204 REGISTER_RESPONSE_HANDLER(
196 gaia_urls->merge_session_url(), HandleMergeSession); 205 gaia_urls->merge_session_url(), HandleMergeSession);
197 206
198 // Handles /o/oauth2/programmatic_auth GAIA call. 207 // Handles /o/oauth2/programmatic_auth GAIA call.
199 REGISTER_RESPONSE_HANDLER( 208 REGISTER_RESPONSE_HANDLER(
200 gaia_urls->client_login_to_oauth2_url(), HandleProgramaticAuth); 209 gaia_urls->client_login_to_oauth2_url(), HandleProgramaticAuth);
201 210
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 } 485 }
477 486
478 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); 487 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT);
479 http_response->AddCustomHeader("Location", redirect_url); 488 http_response->AddCustomHeader("Location", redirect_url);
480 489
481 // SAML sign-ins complete in HandleSSO(). 490 // SAML sign-ins complete in HandleSSO().
482 if (is_saml) 491 if (is_saml)
483 return; 492 return;
484 493
485 AddGoogleAccountsSigninHeader(http_response, email); 494 AddGoogleAccountsSigninHeader(http_response, email);
495 if (issue_oauth_code_cookie_)
496 SetOAuthCodeCookie(http_response);
486 } 497 }
487 498
488 void FakeGaia::HandleSSO(const HttpRequest& request, 499 void FakeGaia::HandleSSO(const HttpRequest& request,
489 BasicHttpResponse* http_response) { 500 BasicHttpResponse* http_response) {
490 if (!merge_session_params_.auth_sid_cookie.empty() && 501 if (!merge_session_params_.auth_sid_cookie.empty() &&
491 !merge_session_params_.auth_lsid_cookie.empty()) { 502 !merge_session_params_.auth_lsid_cookie.empty()) {
492 SetCookies(http_response, 503 SetCookies(http_response,
493 merge_session_params_.auth_sid_cookie, 504 merge_session_params_.auth_sid_cookie,
494 merge_session_params_.auth_lsid_cookie); 505 merge_session_params_.auth_lsid_cookie);
495 } 506 }
496 std::string relay_state; 507 std::string relay_state;
497 GetQueryParameter(request.content, "RelayState", &relay_state); 508 GetQueryParameter(request.content, "RelayState", &relay_state);
498 std::string redirect_url = relay_state; 509 std::string redirect_url = relay_state;
499 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); 510 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT);
500 http_response->AddCustomHeader("Location", redirect_url); 511 http_response->AddCustomHeader("Location", redirect_url);
501 http_response->AddCustomHeader("Google-Accounts-SAML", "End"); 512 http_response->AddCustomHeader("Google-Accounts-SAML", "End");
502 513
503 if (!merge_session_params_.email.empty()) 514 if (!merge_session_params_.email.empty())
504 AddGoogleAccountsSigninHeader(http_response, merge_session_params_.email); 515 AddGoogleAccountsSigninHeader(http_response, merge_session_params_.email);
516
517 if (issue_oauth_code_cookie_)
518 SetOAuthCodeCookie(http_response);
505 } 519 }
506 520
507 void FakeGaia::HandleAuthToken(const HttpRequest& request, 521 void FakeGaia::HandleAuthToken(const HttpRequest& request,
508 BasicHttpResponse* http_response) { 522 BasicHttpResponse* http_response) {
509 std::string grant_type; 523 std::string grant_type;
510 if (!GetQueryParameter(request.content, "grant_type", &grant_type)) { 524 if (!GetQueryParameter(request.content, "grant_type", &grant_type)) {
511 http_response->set_code(net::HTTP_BAD_REQUEST); 525 http_response->set_code(net::HTTP_BAD_REQUEST);
512 LOG(ERROR) << "No 'grant_type' param in /o/oauth2/token"; 526 LOG(ERROR) << "No 'grant_type' param in /o/oauth2/token";
513 return; 527 return;
514 } 528 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 if (token_info) { 646 if (token_info) {
633 base::DictionaryValue response_dict; 647 base::DictionaryValue response_dict;
634 response_dict.SetString("id", GetGaiaIdOfEmail(token_info->email)); 648 response_dict.SetString("id", GetGaiaIdOfEmail(token_info->email));
635 response_dict.SetString("email", token_info->email); 649 response_dict.SetString("email", token_info->email);
636 response_dict.SetString("verified_email", token_info->email); 650 response_dict.SetString("verified_email", token_info->email);
637 FormatJSONResponse(response_dict, http_response); 651 FormatJSONResponse(response_dict, http_response);
638 } else { 652 } else {
639 http_response->set_code(net::HTTP_BAD_REQUEST); 653 http_response->set_code(net::HTTP_BAD_REQUEST);
640 } 654 }
641 } 655 }
OLDNEW
« no previous file with comments | « google_apis/gaia/fake_gaia.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698