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

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

Issue 17009016: Wire up the identity API for enterprise Kiosk Apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | Annotate | Revision Log
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/browser/extensions/api/identity/identity_api.h" 5 #include "chrome/browser/extensions/api/identity/identity_api.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/app_mode/app_mode_utils.h" 17 #include "chrome/browser/app_mode/app_mode_utils.h"
18 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/extensions/extension_function_dispatcher.h" 19 #include "chrome/browser/extensions/extension_function_dispatcher.h"
20 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
21 #include "chrome/browser/policy/browser_policy_connector.h"
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/signin/signin_manager.h" 23 #include "chrome/browser/signin/signin_manager.h"
23 #include "chrome/browser/signin/signin_manager_factory.h" 24 #include "chrome/browser/signin/signin_manager_factory.h"
24 #include "chrome/browser/signin/token_service.h" 25 #include "chrome/browser/signin/token_service.h"
25 #include "chrome/browser/signin/token_service_factory.h" 26 #include "chrome/browser/signin/token_service_factory.h"
26 #include "chrome/common/extensions/api/identity.h" 27 #include "chrome/common/extensions/api/identity.h"
27 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" 28 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h"
28 #include "chrome/common/extensions/extension.h" 29 #include "chrome/common/extensions/extension.h"
29 #include "chrome/common/extensions/extension_manifest_constants.h" 30 #include "chrome/common/extensions/extension_manifest_constants.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
31 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
32 #include "google_apis/gaia/gaia_constants.h" 33 #include "google_apis/gaia/gaia_constants.h"
33 #include "googleurl/src/gurl.h" 34 #include "googleurl/src/gurl.h"
34 35
35 #if defined(OS_CHROMEOS) 36 #if defined(OS_CHROMEOS)
36 #include "chrome/browser/chromeos/login/user_manager.h" 37 #include "chrome/browser/chromeos/login/user_manager.h"
38 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
39 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
37 #endif 40 #endif
38 41
39 namespace extensions { 42 namespace extensions {
40 43
41 namespace identity_constants { 44 namespace identity_constants {
42 const char kInvalidClientId[] = "Invalid OAuth2 Client ID."; 45 const char kInvalidClientId[] = "Invalid OAuth2 Client ID.";
43 const char kInvalidScopes[] = "Invalid OAuth2 scopes."; 46 const char kInvalidScopes[] = "Invalid OAuth2 scopes.";
44 const char kAuthFailure[] = "OAuth2 request failed: "; 47 const char kAuthFailure[] = "OAuth2 request failed: ";
45 const char kNoGrant[] = "OAuth2 not granted or revoked."; 48 const char kNoGrant[] = "OAuth2 not granted or revoked.";
46 const char kUserRejected[] = "The user did not approve access."; 49 const char kUserRejected[] = "The user did not approve access.";
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 96 }
94 97
95 if (oauth2_info.scopes.size() == 0) { 98 if (oauth2_info.scopes.size() == 0) {
96 error_ = identity_constants::kInvalidScopes; 99 error_ = identity_constants::kInvalidScopes;
97 return false; 100 return false;
98 } 101 }
99 102
100 // Balanced in CompleteFunctionWithResult|CompleteFunctionWithError 103 // Balanced in CompleteFunctionWithResult|CompleteFunctionWithError
101 AddRef(); 104 AddRef();
102 105
106 #if defined(OS_CHROMEOS)
107 if (chromeos::UserManager::Get()->IsLoggedInAsKioskApp() &&
108 g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) {
109 OAuth2TokenService::ScopeSet scope_set(oauth2_info.scopes.begin(),
110 oauth2_info.scopes.end());
111 device_token_request_ =
112 chromeos::DeviceOAuth2TokenServiceFactory::Get()->StartRequest(
Michael Courage 2013/06/20 00:19:42 The OAuth2TokenService will request tokens using C
Mattias Nissler (ping if slow) 2013/06/21 02:44:46 I'm aware of that. The any-api refresh token we ha
113 scope_set, this);
114 return true;
115 }
116 #endif
117
103 if (!HasLoginToken()) { 118 if (!HasLoginToken()) {
104 if (!should_prompt_for_signin_) { 119 if (!should_prompt_for_signin_) {
105 error_ = identity_constants::kUserNotSignedIn; 120 error_ = identity_constants::kUserNotSignedIn;
106 Release(); 121 Release();
107 return false; 122 return false;
108 } 123 }
109 // Display a login prompt. 124 // Display a login prompt.
110 StartSigninFlow(); 125 StartSigninFlow();
111 } else { 126 } else {
112 TokenService* token_service = TokenServiceFactory::GetForProfile(profile()); 127 TokenService* token_service = TokenServiceFactory::GetForProfile(profile());
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 IdentityTokenCacheValue token_value( 363 IdentityTokenCacheValue token_value(
349 access_token, base::TimeDelta::FromSeconds(time_to_live)); 364 access_token, base::TimeDelta::FromSeconds(time_to_live));
350 IdentityAPI::GetFactoryInstance()->GetForProfile(profile()) 365 IdentityAPI::GetFactoryInstance()->GetForProfile(profile())
351 ->SetCachedToken(GetExtension()->id(), oauth2_info.scopes, token_value); 366 ->SetCachedToken(GetExtension()->id(), oauth2_info.scopes, token_value);
352 } 367 }
353 368
354 CompleteMintTokenFlow(); 369 CompleteMintTokenFlow();
355 CompleteFunctionWithResult(access_token); 370 CompleteFunctionWithResult(access_token);
356 } 371 }
357 372
373 void IdentityGetAuthTokenFunction::OnGetTokenSuccess(
374 const OAuth2TokenService::Request* request,
375 const std::string& access_token,
376 const base::Time& expiration_time) {
377 DCHECK_EQ(device_token_request_.get(), request);
378 device_token_request_.reset();
379
380 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(GetExtension());
381 IdentityTokenCacheValue token(access_token,
382 expiration_time - base::Time::Now());
383 IdentityAPI::GetFactoryInstance()->GetForProfile(profile())->SetCachedToken(
Michael Courage 2013/06/20 00:19:42 The Kiosk flow in RunImpl diverges before reading
Mattias Nissler (ping if slow) 2013/06/21 02:44:46 Moved token minting to the right place.
384 GetExtension()->id(), oauth2_info.scopes, token);
385
386 CompleteFunctionWithResult(access_token);
387 }
388
389 void IdentityGetAuthTokenFunction::OnGetTokenFailure(
390 const OAuth2TokenService::Request* request,
391 const GoogleServiceAuthError& error) {
392 DCHECK_EQ(device_token_request_.get(), request);
393 device_token_request_.reset();
394
395 CompleteFunctionWithError(error.ToString());
Michael Courage 2013/06/20 00:19:42 There's no way to get all error messages in sync g
Mattias Nissler (ping if slow) 2013/06/21 02:44:46 Done.
396 }
397
358 void IdentityGetAuthTokenFunction::StartGaiaRequest( 398 void IdentityGetAuthTokenFunction::StartGaiaRequest(
359 OAuth2MintTokenFlow::Mode mode) { 399 OAuth2MintTokenFlow::Mode mode) {
360 mint_token_flow_.reset(CreateMintTokenFlow(mode)); 400 mint_token_flow_.reset(CreateMintTokenFlow(mode));
361 mint_token_flow_->Start(); 401 mint_token_flow_->Start();
362 } 402 }
363 403
364 void IdentityGetAuthTokenFunction::ShowLoginPopup() { 404 void IdentityGetAuthTokenFunction::ShowLoginPopup() {
365 signin_flow_.reset(new IdentitySigninFlow(this, profile())); 405 signin_flow_.reset(new IdentitySigninFlow(this, profile()));
366 signin_flow_->Start(); 406 signin_flow_->Start();
367 } 407 }
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 const IdentityAPI::TokenCacheKey& rhs) const { 731 const IdentityAPI::TokenCacheKey& rhs) const {
692 if (extension_id < rhs.extension_id) 732 if (extension_id < rhs.extension_id)
693 return true; 733 return true;
694 else if (rhs.extension_id < extension_id) 734 else if (rhs.extension_id < extension_id)
695 return false; 735 return false;
696 736
697 return scopes < rhs.scopes; 737 return scopes < rhs.scopes;
698 } 738 }
699 739
700 } // namespace extensions 740 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698