1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/chromeos/login/client_login_response_handler.h" 6 7 #include <algorithm> 8 #include <string> 9 10 #include "chrome/browser/chromeos/login/google_authenticator.h" 11 #include "chrome/browser/net/chrome_url_request_context.h" 12 #include "chrome/common/net/url_fetcher.h" 13 #include "net/base/load_flags.h" 14 15 namespace chromeos { 16 17 // By setting "service=gaia", we get an uber-auth-token back. 18 const char ClientLoginResponseHandler::kService[] = "service=gaia"; 19 20 // Overridden from AuthResponseHandler. 21 bool ClientLoginResponseHandler::CanHandle(const GURL& url) { 22 return (url.spec().find(AuthResponseHandler::kClientLoginUrl) != 23 std::string::npos); 24 } 25 26 // Overridden from AuthResponseHandler. 27 URLFetcher* ClientLoginResponseHandler::Handle( 28 const std::string& to_process, 29 URLFetcher::Delegate* catcher) { 30 VLOG(1) << "Handling ClientLogin response!"; 31 payload_.assign(to_process); 32 std::replace(payload_.begin(), payload_.end(), '\n', '&'); 33 payload_.append(kService); 34 35 URLFetcher* fetcher = 36 new URLFetcher(GURL(AuthResponseHandler::kIssueAuthTokenUrl), 37 URLFetcher::POST, 38 catcher); 39 fetcher->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES); 40 fetcher->set_upload_data("application/x-www-form-urlencoded", payload_); 41 if (getter_) { 42 VLOG(1) << "Fetching " << AuthResponseHandler::kIssueAuthTokenUrl; 43 fetcher->set_request_context(getter_); 44 fetcher->Start(); 45 } 46 return fetcher; 47 } 48 49 } // namespace chromeos 50