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

Side by Side Diff: chrome/browser/managed_mode/managed_user_refresh_token_fetcher.cc

Issue 15780020: Setup Sync to use OAuth token for managed users. (Closed) Base URL: http://git.chromium.org/chromium/src.git@issue226464a
Patch Set: fix 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/managed_mode/managed_user_refresh_token_fetcher.h" 5 #include "chrome/browser/managed_mode/managed_user_refresh_token_fetcher.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/signin/oauth2_token_service.h" 14 #include "chrome/browser/signin/oauth2_token_service.h"
15 #include "google_apis/gaia/gaia_constants.h"
15 #include "google_apis/gaia/gaia_oauth_client.h" 16 #include "google_apis/gaia/gaia_oauth_client.h"
16 #include "google_apis/gaia/gaia_urls.h" 17 #include "google_apis/gaia/gaia_urls.h"
17 #include "google_apis/gaia/google_service_auth_error.h" 18 #include "google_apis/gaia/google_service_auth_error.h"
18 #include "google_apis/gaia/oauth2_api_call_flow.h" 19 #include "google_apis/gaia/oauth2_api_call_flow.h"
19 #include "net/base/escape.h" 20 #include "net/base/escape.h"
20 #include "net/base/load_flags.h" 21 #include "net/base/load_flags.h"
21 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
22 #include "net/http/http_status_code.h" 23 #include "net/http/http_status_code.h"
23 #include "net/url_request/url_fetcher.h" 24 #include "net/url_request/url_fetcher.h"
24 #include "net/url_request/url_request_status.h" 25 #include "net/url_request/url_request_status.h"
25 26
26 using base::Time; 27 using base::Time;
27 using gaia::GaiaOAuthClient; 28 using gaia::GaiaOAuthClient;
29 using GaiaConstants::kChromeSyncManagedOAuth2Scope;
28 using net::URLFetcher; 30 using net::URLFetcher;
29 using net::URLFetcherDelegate; 31 using net::URLFetcherDelegate;
30 using net::URLRequestContextGetter; 32 using net::URLRequestContextGetter;
31 33
32 namespace { 34 namespace {
33 35
34 const int kNumRetries = 1; 36 const int kNumRetries = 1;
35 37
36 static const char kChromeSyncManagedScope[] =
37 "https://www.googleapis.com/auth/chromesync_playpen";
38
39 static const char kIssueTokenBodyFormat[] = 38 static const char kIssueTokenBodyFormat[] =
40 "client_id=%s" 39 "client_id=%s"
41 "&scope=%s" 40 "&scope=%s"
42 "&response_type=code" 41 "&response_type=code"
43 "&profile_id=%s" 42 "&profile_id=%s"
44 "&profile_name=%s" 43 "&profile_name=%s"
45 "&device_name=%s"; 44 "&device_name=%s";
46 45
47 static const char kAuthorizationHeaderFormat[] = 46 static const char kAuthorizationHeaderFormat[] =
48 "Authorization: Bearer %s"; 47 "Authorization: Bearer %s";
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 153 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
155 net::LOAD_DO_NOT_SAVE_COOKIES); 154 net::LOAD_DO_NOT_SAVE_COOKIES);
156 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries); 155 url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries);
157 url_fetcher_->AddExtraRequestHeader( 156 url_fetcher_->AddExtraRequestHeader(
158 base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str())); 157 base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str()));
159 158
160 std::string body = base::StringPrintf( 159 std::string body = base::StringPrintf(
161 kIssueTokenBodyFormat, 160 kIssueTokenBodyFormat,
162 net::EscapeUrlEncodedData( 161 net::EscapeUrlEncodedData(
163 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true).c_str(), 162 GaiaUrls::GetInstance()->oauth2_chrome_client_id(), true).c_str(),
164 net::EscapeUrlEncodedData(kChromeSyncManagedScope, true).c_str(), 163 net::EscapeUrlEncodedData(kChromeSyncManagedOAuth2Scope, true).c_str(),
165 net::EscapeUrlEncodedData(managed_user_id_, true).c_str(), 164 net::EscapeUrlEncodedData(managed_user_id_, true).c_str(),
166 net::EscapeUrlEncodedData(UTF16ToUTF8(name_), true).c_str(), 165 net::EscapeUrlEncodedData(UTF16ToUTF8(name_), true).c_str(),
167 net::EscapeUrlEncodedData(device_name_, true).c_str()); 166 net::EscapeUrlEncodedData(device_name_, true).c_str());
168 url_fetcher_->SetUploadData("application/x-www-form-urlencoded", body); 167 url_fetcher_->SetUploadData("application/x-www-form-urlencoded", body);
169 168
170 url_fetcher_->Start(); 169 url_fetcher_->Start();
171 } 170 }
172 171
173 void ManagedUserRefreshTokenFetcherImpl::OnGetTokenFailure( 172 void ManagedUserRefreshTokenFetcherImpl::OnGetTokenFailure(
174 const OAuth2TokenService::Request* request, 173 const OAuth2TokenService::Request* request,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // static 275 // static
277 scoped_ptr<ManagedUserRefreshTokenFetcher> 276 scoped_ptr<ManagedUserRefreshTokenFetcher>
278 ManagedUserRefreshTokenFetcher::Create(OAuth2TokenService* oauth2_token_service, 277 ManagedUserRefreshTokenFetcher::Create(OAuth2TokenService* oauth2_token_service,
279 URLRequestContextGetter* context) { 278 URLRequestContextGetter* context) {
280 scoped_ptr<ManagedUserRefreshTokenFetcher> fetcher( 279 scoped_ptr<ManagedUserRefreshTokenFetcher> fetcher(
281 new ManagedUserRefreshTokenFetcherImpl(oauth2_token_service, context)); 280 new ManagedUserRefreshTokenFetcherImpl(oauth2_token_service, context));
282 return fetcher.Pass(); 281 return fetcher.Pass();
283 } 282 }
284 283
285 ManagedUserRefreshTokenFetcher::~ManagedUserRefreshTokenFetcher() {} 284 ManagedUserRefreshTokenFetcher::~ManagedUserRefreshTokenFetcher() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698