| 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/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "chrome/common/cloud_print/cloud_print_constants.h" | 9 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 10 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 10 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 void CloudPrintAuth::AuthenticateWithRobotAuthCode( | 57 void CloudPrintAuth::AuthenticateWithRobotAuthCode( |
| 58 const std::string& robot_oauth_auth_code, | 58 const std::string& robot_oauth_auth_code, |
| 59 const std::string& robot_email) { | 59 const std::string& robot_email) { |
| 60 VLOG(1) << "CP_AUTH: Authenticating with robot auth code"; | 60 VLOG(1) << "CP_AUTH: Authenticating with robot auth code"; |
| 61 | 61 |
| 62 robot_email_ = robot_email; | 62 robot_email_ = robot_email; |
| 63 // Now that we have an auth code we need to get the refresh and access tokens. | 63 // Now that we have an auth code we need to get the refresh and access tokens. |
| 64 oauth_client_.reset(new gaia::GaiaOAuthClient( | 64 oauth_client_.reset(new gaia::GaiaOAuthClient( |
| 65 GaiaUrls::GetInstance()->oauth2_token_url(), | |
| 66 g_service_process->GetServiceURLRequestContextGetter())); | 65 g_service_process->GetServiceURLRequestContextGetter())); |
| 67 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, | 66 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, |
| 68 robot_oauth_auth_code, | 67 robot_oauth_auth_code, |
| 69 kCloudPrintAuthMaxRetryCount, | 68 kCloudPrintAuthMaxRetryCount, |
| 70 this); | 69 this); |
| 71 } | 70 } |
| 72 | 71 |
| 73 void CloudPrintAuth::RefreshAccessToken() { | 72 void CloudPrintAuth::RefreshAccessToken() { |
| 74 oauth_client_.reset(new gaia::GaiaOAuthClient( | 73 oauth_client_.reset(new gaia::GaiaOAuthClient( |
| 75 GaiaUrls::GetInstance()->oauth2_token_url(), | |
| 76 g_service_process->GetServiceURLRequestContextGetter())); | 74 g_service_process->GetServiceURLRequestContextGetter())); |
| 75 std::vector<std::string> empty_scope_list; // (Use scope from refresh token.) |
| 77 oauth_client_->RefreshToken(oauth_client_info_, | 76 oauth_client_->RefreshToken(oauth_client_info_, |
| 78 refresh_token_, | 77 refresh_token_, |
| 78 empty_scope_list, |
| 79 kCloudPrintAuthMaxRetryCount, | 79 kCloudPrintAuthMaxRetryCount, |
| 80 this); | 80 this); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void CloudPrintAuth::OnGetTokensResponse(const std::string& refresh_token, | 83 void CloudPrintAuth::OnGetTokensResponse(const std::string& refresh_token, |
| 84 const std::string& access_token, | 84 const std::string& access_token, |
| 85 int expires_in_seconds) { | 85 int expires_in_seconds) { |
| 86 refresh_token_ = refresh_token; | 86 refresh_token_ = refresh_token; |
| 87 // After saving the refresh token, this is just like having just refreshed | 87 // After saving the refresh token, this is just like having just refreshed |
| 88 // the access token. Just call OnRefreshTokenResponse. | 88 // the access token. Just call OnRefreshTokenResponse. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 std::string auth_code; | 132 std::string auth_code; |
| 133 if (!json_data->GetString(kOAuthCodeValue, &auth_code)) { | 133 if (!json_data->GetString(kOAuthCodeValue, &auth_code)) { |
| 134 VLOG(1) << "CP_AUTH: Creating robot account returned invalid json response"; | 134 VLOG(1) << "CP_AUTH: Creating robot account returned invalid json response"; |
| 135 client_->OnInvalidCredentials(); | 135 client_->OnInvalidCredentials(); |
| 136 return CloudPrintURLFetcher::STOP_PROCESSING; | 136 return CloudPrintURLFetcher::STOP_PROCESSING; |
| 137 } | 137 } |
| 138 | 138 |
| 139 json_data->GetString(kXMPPJidValue, &robot_email_); | 139 json_data->GetString(kXMPPJidValue, &robot_email_); |
| 140 // Now that we have an auth code we need to get the refresh and access tokens. | 140 // Now that we have an auth code we need to get the refresh and access tokens. |
| 141 oauth_client_.reset(new gaia::GaiaOAuthClient( | 141 oauth_client_.reset(new gaia::GaiaOAuthClient( |
| 142 GaiaUrls::GetInstance()->oauth2_token_url(), | |
| 143 g_service_process->GetServiceURLRequestContextGetter())); | 142 g_service_process->GetServiceURLRequestContextGetter())); |
| 144 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, | 143 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, |
| 145 auth_code, | 144 auth_code, |
| 146 kCloudPrintAPIMaxRetryCount, | 145 kCloudPrintAPIMaxRetryCount, |
| 147 this); | 146 this); |
| 148 | 147 |
| 149 return CloudPrintURLFetcher::STOP_PROCESSING; | 148 return CloudPrintURLFetcher::STOP_PROCESSING; |
| 150 } | 149 } |
| 151 | 150 |
| 152 CloudPrintURLFetcher::ResponseAction CloudPrintAuth::OnRequestAuthError() { | 151 CloudPrintURLFetcher::ResponseAction CloudPrintAuth::OnRequestAuthError() { |
| 153 VLOG(1) << "CP_AUTH: Creating robot account authentication error"; | 152 VLOG(1) << "CP_AUTH: Creating robot account authentication error"; |
| 154 // Notify client about authentication error. | 153 // Notify client about authentication error. |
| 155 client_->OnInvalidCredentials(); | 154 client_->OnInvalidCredentials(); |
| 156 return CloudPrintURLFetcher::STOP_PROCESSING; | 155 return CloudPrintURLFetcher::STOP_PROCESSING; |
| 157 } | 156 } |
| 158 | 157 |
| 159 std::string CloudPrintAuth::GetAuthHeader() { | 158 std::string CloudPrintAuth::GetAuthHeader() { |
| 160 DCHECK(!client_login_token_.empty()); | 159 DCHECK(!client_login_token_.empty()); |
| 161 std::string header; | 160 std::string header; |
| 162 header = "Authorization: GoogleLogin auth="; | 161 header = "Authorization: GoogleLogin auth="; |
| 163 header += client_login_token_; | 162 header += client_login_token_; |
| 164 return header; | 163 return header; |
| 165 } | 164 } |
| 166 | 165 |
| 167 CloudPrintAuth::~CloudPrintAuth() {} | 166 CloudPrintAuth::~CloudPrintAuth() {} |
| 168 | 167 |
| 169 } // namespace cloud_print | 168 } // namespace cloud_print |
| OLD | NEW |