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_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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 void CloudPrintAuth::AuthenticateWithRobotAuthCode( | 90 void CloudPrintAuth::AuthenticateWithRobotAuthCode( |
91 const std::string& robot_oauth_auth_code, | 91 const std::string& robot_oauth_auth_code, |
92 const std::string& robot_email) { | 92 const std::string& robot_email) { |
93 VLOG(1) << "CP_AUTH: Authenticating with robot auth code"; | 93 VLOG(1) << "CP_AUTH: Authenticating with robot auth code"; |
94 | 94 |
95 robot_email_ = robot_email; | 95 robot_email_ = robot_email; |
96 // Now that we have an auth code we need to get the refresh and access tokens. | 96 // Now that we have an auth code we need to get the refresh and access tokens. |
97 oauth_client_.reset(new gaia::GaiaOAuthClient( | 97 oauth_client_.reset(new gaia::GaiaOAuthClient( |
98 gaia::kGaiaOAuth2Url, | 98 GaiaUrls::GetInstance()->oauth2_token_url(), |
99 g_service_process->GetServiceURLRequestContextGetter())); | 99 g_service_process->GetServiceURLRequestContextGetter())); |
100 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, | 100 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, |
101 robot_oauth_auth_code, | 101 robot_oauth_auth_code, |
102 kCloudPrintAuthMaxRetryCount, | 102 kCloudPrintAuthMaxRetryCount, |
103 this); | 103 this); |
104 } | 104 } |
105 | 105 |
106 void CloudPrintAuth::RefreshAccessToken() { | 106 void CloudPrintAuth::RefreshAccessToken() { |
107 oauth_client_.reset(new gaia::GaiaOAuthClient( | 107 oauth_client_.reset(new gaia::GaiaOAuthClient( |
108 gaia::kGaiaOAuth2Url, | 108 GaiaUrls::GetInstance()->oauth2_token_url(), |
109 g_service_process->GetServiceURLRequestContextGetter())); | 109 g_service_process->GetServiceURLRequestContextGetter())); |
110 oauth_client_->RefreshToken(oauth_client_info_, | 110 oauth_client_->RefreshToken(oauth_client_info_, |
111 refresh_token_, | 111 refresh_token_, |
112 kCloudPrintAuthMaxRetryCount, | 112 kCloudPrintAuthMaxRetryCount, |
113 this); | 113 this); |
114 } | 114 } |
115 | 115 |
116 void CloudPrintAuth::OnGetTokensResponse(const std::string& refresh_token, | 116 void CloudPrintAuth::OnGetTokensResponse(const std::string& refresh_token, |
117 const std::string& access_token, | 117 const std::string& access_token, |
118 int expires_in_seconds) { | 118 int expires_in_seconds) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 std::string auth_code; | 164 std::string auth_code; |
165 if (!json_data->GetString(kOAuthCodeValue, &auth_code)) { | 165 if (!json_data->GetString(kOAuthCodeValue, &auth_code)) { |
166 VLOG(1) << "CP_AUTH: Creating robot account returned invalid json response"; | 166 VLOG(1) << "CP_AUTH: Creating robot account returned invalid json response"; |
167 client_->OnInvalidCredentials(); | 167 client_->OnInvalidCredentials(); |
168 return CloudPrintURLFetcher::STOP_PROCESSING; | 168 return CloudPrintURLFetcher::STOP_PROCESSING; |
169 } | 169 } |
170 | 170 |
171 json_data->GetString(kXMPPJidValue, &robot_email_); | 171 json_data->GetString(kXMPPJidValue, &robot_email_); |
172 // Now that we have an auth code we need to get the refresh and access tokens. | 172 // Now that we have an auth code we need to get the refresh and access tokens. |
173 oauth_client_.reset(new gaia::GaiaOAuthClient( | 173 oauth_client_.reset(new gaia::GaiaOAuthClient( |
174 gaia::kGaiaOAuth2Url, | 174 GaiaUrls::GetInstance()->oauth2_token_url(), |
175 g_service_process->GetServiceURLRequestContextGetter())); | 175 g_service_process->GetServiceURLRequestContextGetter())); |
176 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, | 176 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, |
177 auth_code, | 177 auth_code, |
178 kCloudPrintAPIMaxRetryCount, | 178 kCloudPrintAPIMaxRetryCount, |
179 this); | 179 this); |
180 | 180 |
181 return CloudPrintURLFetcher::STOP_PROCESSING; | 181 return CloudPrintURLFetcher::STOP_PROCESSING; |
182 } | 182 } |
183 | 183 |
184 CloudPrintURLFetcher::ResponseAction CloudPrintAuth::OnRequestAuthError() { | 184 CloudPrintURLFetcher::ResponseAction CloudPrintAuth::OnRequestAuthError() { |
185 VLOG(1) << "CP_AUTH: Creating robot account authentication error"; | 185 VLOG(1) << "CP_AUTH: Creating robot account authentication error"; |
186 // Notify client about authentication error. | 186 // Notify client about authentication error. |
187 client_->OnInvalidCredentials(); | 187 client_->OnInvalidCredentials(); |
188 return CloudPrintURLFetcher::STOP_PROCESSING; | 188 return CloudPrintURLFetcher::STOP_PROCESSING; |
189 } | 189 } |
190 | 190 |
191 std::string CloudPrintAuth::GetAuthHeader() { | 191 std::string CloudPrintAuth::GetAuthHeader() { |
192 DCHECK(!client_login_token_.empty()); | 192 DCHECK(!client_login_token_.empty()); |
193 std::string header; | 193 std::string header; |
194 header = "Authorization: GoogleLogin auth="; | 194 header = "Authorization: GoogleLogin auth="; |
195 header += client_login_token_; | 195 header += client_login_token_; |
196 return header; | 196 return header; |
197 } | 197 } |
198 | 198 |
199 CloudPrintAuth::~CloudPrintAuth() {} | 199 CloudPrintAuth::~CloudPrintAuth() {} |
200 | 200 |
201 } // namespace cloud_print | 201 } // namespace cloud_print |
OLD | NEW |