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

Side by Side Diff: chrome/browser/extensions/api/identity/gaia_web_auth_flow.cc

Issue 693203003: Pass device_id/device_type to web flow token approval url. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittests. Created 6 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/extensions/api/identity/gaia_web_auth_flow.h" 5 #include "chrome/browser/extensions/api/identity/gaia_web_auth_flow.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/signin/chrome_signin_client_factory.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
14 #include "chrome/browser/signin/signin_manager_factory.h" 15 #include "chrome/browser/signin/signin_manager_factory.h"
15 #include "components/signin/core/browser/profile_oauth2_token_service.h" 16 #include "components/signin/core/browser/profile_oauth2_token_service.h"
16 #include "components/signin/core/browser/signin_manager.h" 17 #include "components/signin/core/browser/signin_manager.h"
17 #include "google_apis/gaia/gaia_constants.h" 18 #include "google_apis/gaia/gaia_constants.h"
18 #include "google_apis/gaia/gaia_urls.h" 19 #include "google_apis/gaia/gaia_urls.h"
19 #include "net/base/escape.h" 20 #include "net/base/escape.h"
20 21
21 namespace extensions { 22 namespace extensions {
22 23
(...skipping 14 matching lines...) Expand all
37 token_key->account_id); 38 token_key->account_id);
38 39
39 const char kOAuth2RedirectPathFormat[] = "/%s#"; 40 const char kOAuth2RedirectPathFormat[] = "/%s#";
40 const char kOAuth2AuthorizeFormat[] = 41 const char kOAuth2AuthorizeFormat[] =
41 "?response_type=token&approval_prompt=force&authuser=0&" 42 "?response_type=token&approval_prompt=force&authuser=0&"
42 "client_id=%s&" 43 "client_id=%s&"
43 "scope=%s&" 44 "scope=%s&"
44 "origin=chrome-extension://%s/&" 45 "origin=chrome-extension://%s/&"
45 "redirect_uri=%s:/%s&" 46 "redirect_uri=%s:/%s&"
46 "hl=%s"; 47 "hl=%s";
48 // Additional parameters to pass if device_id is enabled.
49 const char kOAuth2AuthorizeFormatDeviceIdAddendum[] =
50 "&device_id=%s&"
51 "device_type=chrome";
47 52
48 std::vector<std::string> scopes(token_key->scopes.begin(), 53 std::vector<std::string> scopes(token_key->scopes.begin(),
49 token_key->scopes.end()); 54 token_key->scopes.end());
50 std::vector<std::string> client_id_parts; 55 std::vector<std::string> client_id_parts;
51 base::SplitString(oauth2_client_id, '.', &client_id_parts); 56 base::SplitString(oauth2_client_id, '.', &client_id_parts);
52 std::reverse(client_id_parts.begin(), client_id_parts.end()); 57 std::reverse(client_id_parts.begin(), client_id_parts.end());
53 redirect_scheme_ = JoinString(client_id_parts, '.'); 58 redirect_scheme_ = JoinString(client_id_parts, '.');
59 std::string signin_scoped_device_id;
60 // profile_ can be nullptr in unittests.
61 SigninClient* signin_client =
62 profile_ ? ChromeSigninClientFactory::GetForProfile(profile_) : nullptr;
63 if (signin_client)
64 signin_scoped_device_id = signin_client->GetSigninScopedDeviceId();
54 65
55 redirect_path_prefix_ = base::StringPrintf(kOAuth2RedirectPathFormat, 66 redirect_path_prefix_ = base::StringPrintf(kOAuth2RedirectPathFormat,
56 token_key->extension_id.c_str()); 67 token_key->extension_id.c_str());
57 68
58 auth_url_ = 69 std::string oauth2_authorize_params = base::StringPrintf(
59 GaiaUrls::GetInstance()->oauth2_auth_url().Resolve(base::StringPrintf( 70 kOAuth2AuthorizeFormat,
60 kOAuth2AuthorizeFormat, 71 oauth2_client_id.c_str(),
61 oauth2_client_id.c_str(), 72 net::EscapeUrlEncodedData(JoinString(scopes, ' '), true).c_str(),
62 net::EscapeUrlEncodedData(JoinString(scopes, ' '), true).c_str(), 73 token_key->extension_id.c_str(),
63 token_key->extension_id.c_str(), 74 redirect_scheme_.c_str(),
64 redirect_scheme_.c_str(), 75 token_key->extension_id.c_str(),
65 token_key->extension_id.c_str(), 76 locale.c_str());
66 locale.c_str())); 77 if (!signin_scoped_device_id.empty()) {
78 oauth2_authorize_params += base::StringPrintf(
79 kOAuth2AuthorizeFormatDeviceIdAddendum,
80 net::EscapeUrlEncodedData(signin_scoped_device_id, true).c_str());
81 }
82 auth_url_ = GaiaUrls::GetInstance()->oauth2_auth_url().Resolve(
83 oauth2_authorize_params);
67 } 84 }
68 85
69 GaiaWebAuthFlow::~GaiaWebAuthFlow() { 86 GaiaWebAuthFlow::~GaiaWebAuthFlow() {
70 TRACE_EVENT_ASYNC_END0("identity", "GaiaWebAuthFlow", this); 87 TRACE_EVENT_ASYNC_END0("identity", "GaiaWebAuthFlow", this);
71 88
72 if (web_flow_) 89 if (web_flow_)
73 web_flow_.release()->DetachDelegateAndDelete(); 90 web_flow_.release()->DetachDelegateAndDelete();
74 } 91 }
75 92
76 void GaiaWebAuthFlow::Start() { 93 void GaiaWebAuthFlow::Start() {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 231 }
215 232
216 scoped_ptr<WebAuthFlow> GaiaWebAuthFlow::CreateWebAuthFlow(GURL url) { 233 scoped_ptr<WebAuthFlow> GaiaWebAuthFlow::CreateWebAuthFlow(GURL url) {
217 return scoped_ptr<WebAuthFlow>(new WebAuthFlow(this, 234 return scoped_ptr<WebAuthFlow>(new WebAuthFlow(this,
218 profile_, 235 profile_,
219 url, 236 url,
220 WebAuthFlow::INTERACTIVE)); 237 WebAuthFlow::INTERACTIVE));
221 } 238 }
222 239
223 } // namespace extensions 240 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698