| OLD | NEW |
| 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 "chrome/service/cloud_print/cloud_print_auth.h" | 5 #include "chrome/service/cloud_print/cloud_print_auth.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/common/cloud_print/cloud_print_consts.h" |
| 10 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
| 9 #include "chrome/service/cloud_print/cloud_print_consts.h" | 11 #include "chrome/service/cloud_print/cloud_print_consts.h" |
| 10 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 12 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
| 11 #include "chrome/service/cloud_print/cloud_print_token_store.h" | 13 #include "chrome/service/cloud_print/cloud_print_token_store.h" |
| 12 #include "chrome/service/gaia/service_gaia_authenticator.h" | 14 #include "chrome/service/gaia/service_gaia_authenticator.h" |
| 13 #include "chrome/service/net/service_url_request_context.h" | 15 #include "chrome/service/net/service_url_request_context.h" |
| 14 #include "chrome/service/service_process.h" | 16 #include "chrome/service/service_process.h" |
| 15 #include "google_apis/gaia/gaia_urls.h" | 17 #include "google_apis/gaia/gaia_urls.h" |
| 16 | 18 |
| 17 CloudPrintAuth::CloudPrintAuth( | 19 CloudPrintAuth::CloudPrintAuth( |
| 18 Client* client, | 20 Client* client, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 61 } |
| 60 | 62 |
| 61 void CloudPrintAuth::AuthenticateWithToken( | 63 void CloudPrintAuth::AuthenticateWithToken( |
| 62 const std::string& cloud_print_token) { | 64 const std::string& cloud_print_token) { |
| 63 VLOG(1) << "CP_AUTH: Authenticating with token"; | 65 VLOG(1) << "CP_AUTH: Authenticating with token"; |
| 64 | 66 |
| 65 client_login_token_ = cloud_print_token; | 67 client_login_token_ = cloud_print_token; |
| 66 | 68 |
| 67 // We need to get the credentials of the robot here. | 69 // We need to get the credentials of the robot here. |
| 68 GURL get_authcode_url = | 70 GURL get_authcode_url = |
| 69 CloudPrintHelpers::GetUrlForGetAuthCode(cloud_print_server_url_, | 71 cloud_print::GetUrlForGetAuthCode(cloud_print_server_url_, |
| 70 oauth_client_info_.client_id, | 72 oauth_client_info_.client_id, |
| 71 proxy_id_); | 73 proxy_id_); |
| 72 request_ = new CloudPrintURLFetcher; | 74 request_ = new CloudPrintURLFetcher; |
| 73 request_->StartGetRequest(get_authcode_url, | 75 request_->StartGetRequest(get_authcode_url, |
| 74 this, | 76 this, |
| 75 kCloudPrintAuthMaxRetryCount, | 77 kCloudPrintAuthMaxRetryCount, |
| 76 std::string()); | 78 std::string()); |
| 77 } | 79 } |
| 78 | 80 |
| 79 void CloudPrintAuth::AuthenticateWithRobotToken( | 81 void CloudPrintAuth::AuthenticateWithRobotToken( |
| 80 const std::string& robot_oauth_refresh_token, | 82 const std::string& robot_oauth_refresh_token, |
| 81 const std::string& robot_email) { | 83 const std::string& robot_email) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 const GURL& url, | 156 const GURL& url, |
| 155 base::DictionaryValue* json_data, | 157 base::DictionaryValue* json_data, |
| 156 bool succeeded) { | 158 bool succeeded) { |
| 157 if (!succeeded) { | 159 if (!succeeded) { |
| 158 VLOG(1) << "CP_AUTH: Creating robot account failed"; | 160 VLOG(1) << "CP_AUTH: Creating robot account failed"; |
| 159 client_->OnInvalidCredentials(); | 161 client_->OnInvalidCredentials(); |
| 160 return CloudPrintURLFetcher::STOP_PROCESSING; | 162 return CloudPrintURLFetcher::STOP_PROCESSING; |
| 161 } | 163 } |
| 162 | 164 |
| 163 std::string auth_code; | 165 std::string auth_code; |
| 164 if (!json_data->GetString(kOAuthCodeValue, &auth_code)) { | 166 if (!json_data->GetString(cloud_print::kOAuthCodeValue, &auth_code)) { |
| 165 VLOG(1) << "CP_AUTH: Creating robot account returned invalid json response"; | 167 VLOG(1) << "CP_AUTH: Creating robot account returned invalid json response"; |
| 166 client_->OnInvalidCredentials(); | 168 client_->OnInvalidCredentials(); |
| 167 return CloudPrintURLFetcher::STOP_PROCESSING; | 169 return CloudPrintURLFetcher::STOP_PROCESSING; |
| 168 } | 170 } |
| 169 | 171 |
| 170 json_data->GetString(kXMPPJidValue, &robot_email_); | 172 json_data->GetString(cloud_print::kXMPPJidValue, &robot_email_); |
| 171 // Now that we have an auth code we need to get the refresh and access tokens. | 173 // Now that we have an auth code we need to get the refresh and access tokens. |
| 172 oauth_client_.reset(new gaia::GaiaOAuthClient( | 174 oauth_client_.reset(new gaia::GaiaOAuthClient( |
| 173 gaia::kGaiaOAuth2Url, | 175 gaia::kGaiaOAuth2Url, |
| 174 g_service_process->GetServiceURLRequestContextGetter())); | 176 g_service_process->GetServiceURLRequestContextGetter())); |
| 175 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, | 177 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, |
| 176 auth_code, | 178 auth_code, |
| 177 kCloudPrintAPIMaxRetryCount, | 179 kCloudPrintAPIMaxRetryCount, |
| 178 this); | 180 this); |
| 179 | 181 |
| 180 return CloudPrintURLFetcher::STOP_PROCESSING; | 182 return CloudPrintURLFetcher::STOP_PROCESSING; |
| 181 } | 183 } |
| 182 | 184 |
| 183 CloudPrintURLFetcher::ResponseAction CloudPrintAuth::OnRequestAuthError() { | 185 CloudPrintURLFetcher::ResponseAction CloudPrintAuth::OnRequestAuthError() { |
| 184 VLOG(1) << "CP_AUTH: Creating robot account authentication error"; | 186 VLOG(1) << "CP_AUTH: Creating robot account authentication error"; |
| 185 // Notify client about authentication error. | 187 // Notify client about authentication error. |
| 186 client_->OnInvalidCredentials(); | 188 client_->OnInvalidCredentials(); |
| 187 return CloudPrintURLFetcher::STOP_PROCESSING; | 189 return CloudPrintURLFetcher::STOP_PROCESSING; |
| 188 } | 190 } |
| 189 | 191 |
| 190 std::string CloudPrintAuth::GetAuthHeader() { | 192 std::string CloudPrintAuth::GetAuthHeader() { |
| 191 DCHECK(!client_login_token_.empty()); | 193 DCHECK(!client_login_token_.empty()); |
| 192 std::string header; | 194 std::string header; |
| 193 header = "Authorization: GoogleLogin auth="; | 195 header = "Authorization: GoogleLogin auth="; |
| 194 header += client_login_token_; | 196 header += client_login_token_; |
| 195 return header; | 197 return header; |
| 196 } | 198 } |
| 197 | 199 |
| 198 CloudPrintAuth::~CloudPrintAuth() {} | 200 CloudPrintAuth::~CloudPrintAuth() {} |
| 199 | 201 |
| OLD | NEW |