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

Side by Side Diff: chrome/service/cloud_print/cloud_print_auth.cc

Issue 17109006: Device robot refresh token integrity validation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: addressed atwilson's review comments Created 7 years, 6 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
OLDNEW
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
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 GaiaUrls::GetInstance()->oauth2_token_url(),
99 g_service_process->GetServiceURLRequestContextGetter())); 98 g_service_process->GetServiceURLRequestContextGetter()));
100 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, 99 oauth_client_->GetTokensFromAuthCode(oauth_client_info_,
101 robot_oauth_auth_code, 100 robot_oauth_auth_code,
102 kCloudPrintAuthMaxRetryCount, 101 kCloudPrintAuthMaxRetryCount,
103 this); 102 this);
104 } 103 }
105 104
106 void CloudPrintAuth::RefreshAccessToken() { 105 void CloudPrintAuth::RefreshAccessToken() {
107 oauth_client_.reset(new gaia::GaiaOAuthClient( 106 oauth_client_.reset(new gaia::GaiaOAuthClient(
108 GaiaUrls::GetInstance()->oauth2_token_url(),
109 g_service_process->GetServiceURLRequestContextGetter())); 107 g_service_process->GetServiceURLRequestContextGetter()));
108 std::vector<std::string> empty_scope_list; // (Use scope from refresh token.)
110 oauth_client_->RefreshToken(oauth_client_info_, 109 oauth_client_->RefreshToken(oauth_client_info_,
111 refresh_token_, 110 refresh_token_,
111 empty_scope_list,
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) {
119 refresh_token_ = refresh_token; 119 refresh_token_ = refresh_token;
120 // After saving the refresh token, this is just like having just refreshed 120 // After saving the refresh token, this is just like having just refreshed
121 // the access token. Just call OnRefreshTokenResponse. 121 // the access token. Just call OnRefreshTokenResponse.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 std::string auth_code; 165 std::string auth_code;
166 if (!json_data->GetString(kOAuthCodeValue, &auth_code)) { 166 if (!json_data->GetString(kOAuthCodeValue, &auth_code)) {
167 VLOG(1) << "CP_AUTH: Creating robot account returned invalid json response"; 167 VLOG(1) << "CP_AUTH: Creating robot account returned invalid json response";
168 client_->OnInvalidCredentials(); 168 client_->OnInvalidCredentials();
169 return CloudPrintURLFetcher::STOP_PROCESSING; 169 return CloudPrintURLFetcher::STOP_PROCESSING;
170 } 170 }
171 171
172 json_data->GetString(kXMPPJidValue, &robot_email_); 172 json_data->GetString(kXMPPJidValue, &robot_email_);
173 // 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.
174 oauth_client_.reset(new gaia::GaiaOAuthClient( 174 oauth_client_.reset(new gaia::GaiaOAuthClient(
175 GaiaUrls::GetInstance()->oauth2_token_url(),
176 g_service_process->GetServiceURLRequestContextGetter())); 175 g_service_process->GetServiceURLRequestContextGetter()));
177 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, 176 oauth_client_->GetTokensFromAuthCode(oauth_client_info_,
178 auth_code, 177 auth_code,
179 kCloudPrintAPIMaxRetryCount, 178 kCloudPrintAPIMaxRetryCount,
180 this); 179 this);
181 180
182 return CloudPrintURLFetcher::STOP_PROCESSING; 181 return CloudPrintURLFetcher::STOP_PROCESSING;
183 } 182 }
184 183
185 CloudPrintURLFetcher::ResponseAction CloudPrintAuth::OnRequestAuthError() { 184 CloudPrintURLFetcher::ResponseAction CloudPrintAuth::OnRequestAuthError() {
186 VLOG(1) << "CP_AUTH: Creating robot account authentication error"; 185 VLOG(1) << "CP_AUTH: Creating robot account authentication error";
187 // Notify client about authentication error. 186 // Notify client about authentication error.
188 client_->OnInvalidCredentials(); 187 client_->OnInvalidCredentials();
189 return CloudPrintURLFetcher::STOP_PROCESSING; 188 return CloudPrintURLFetcher::STOP_PROCESSING;
190 } 189 }
191 190
192 std::string CloudPrintAuth::GetAuthHeader() { 191 std::string CloudPrintAuth::GetAuthHeader() {
193 DCHECK(!client_login_token_.empty()); 192 DCHECK(!client_login_token_.empty());
194 std::string header; 193 std::string header;
195 header = "Authorization: GoogleLogin auth="; 194 header = "Authorization: GoogleLogin auth=";
196 header += client_login_token_; 195 header += client_login_token_;
197 return header; 196 return header;
198 } 197 }
199 198
200 CloudPrintAuth::~CloudPrintAuth() {} 199 CloudPrintAuth::~CloudPrintAuth() {}
201 200
202 } // namespace cloud_print 201 } // namespace cloud_print
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698