Chromium Code Reviews| 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/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> |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 const char kCanceled[] = "canceled"; | 65 const char kCanceled[] = "canceled"; |
| 66 | 66 |
| 67 const int kCachedIssueAdviceTTLSeconds = 1; | 67 const int kCachedIssueAdviceTTLSeconds = 1; |
| 68 } // namespace identity_constants | 68 } // namespace identity_constants |
| 69 | 69 |
| 70 namespace { | 70 namespace { |
| 71 | 71 |
| 72 static const char kChromiumDomainRedirectUrlPattern[] = | 72 static const char kChromiumDomainRedirectUrlPattern[] = |
| 73 "https://%s.chromiumapp.org/"; | 73 "https://%s.chromiumapp.org/"; |
| 74 | 74 |
| 75 #if defined(OS_CHROMEOS) | |
| 76 // The list of apps that are allowed to use the Identity API to retrieve the | |
| 77 // token from the device robot account in a public session. | |
| 78 const char* const kPublicSessionAllowedOrigins[] = { | |
| 79 // Chrome Remote Desktop - Chromium branding. | |
| 80 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/", | |
| 81 // Chrome Remote Desktop - Official branding. | |
| 82 "chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/"}; | |
| 83 #endif | |
| 84 | |
| 75 std::string GetPrimaryAccountId(content::BrowserContext* context) { | 85 std::string GetPrimaryAccountId(content::BrowserContext* context) { |
| 76 SigninManagerBase* signin_manager = | 86 SigninManagerBase* signin_manager = |
| 77 SigninManagerFactory::GetForProfile(Profile::FromBrowserContext(context)); | 87 SigninManagerFactory::GetForProfile(Profile::FromBrowserContext(context)); |
| 78 return signin_manager->GetAuthenticatedAccountId(); | 88 return signin_manager->GetAuthenticatedAccountId(); |
| 79 } | 89 } |
| 80 | 90 |
| 81 } // namespace | 91 } // namespace |
| 82 | 92 |
| 83 namespace identity = api::identity; | 93 namespace identity = api::identity; |
| 84 | 94 |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 | 374 |
| 365 token_key_.reset( | 375 token_key_.reset( |
| 366 new ExtensionTokenKey(extension()->id(), account_key, scopes)); | 376 new ExtensionTokenKey(extension()->id(), account_key, scopes)); |
| 367 | 377 |
| 368 // From here on out, results must be returned asynchronously. | 378 // From here on out, results must be returned asynchronously. |
| 369 StartAsyncRun(); | 379 StartAsyncRun(); |
| 370 | 380 |
| 371 #if defined(OS_CHROMEOS) | 381 #if defined(OS_CHROMEOS) |
| 372 policy::BrowserPolicyConnectorChromeOS* connector = | 382 policy::BrowserPolicyConnectorChromeOS* connector = |
| 373 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 383 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 374 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp() && | 384 bool is_kiosk = user_manager::UserManager::Get()->IsLoggedInAsKioskApp(); |
| 375 connector->IsEnterpriseManaged()) { | 385 bool is_public_session = |
| 386 user_manager::UserManager::Get()->IsLoggedInAsPublicAccount(); | |
| 387 | |
| 388 if (connector->IsEnterpriseManaged() && (is_kiosk || is_public_session)) { | |
| 389 if (is_public_session && !IsOriginWhitelistedInPublicSession()) { | |
| 390 CompleteFunctionWithError(identity_constants::kUserNotSignedIn); | |
| 391 return true; | |
| 392 } | |
| 393 | |
| 376 StartMintTokenFlow(IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE); | 394 StartMintTokenFlow(IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE); |
| 377 return true; | 395 return true; |
| 378 } | 396 } |
| 379 #endif | 397 #endif |
| 380 | 398 |
| 381 if (!HasLoginToken()) { | 399 if (!HasLoginToken()) { |
| 382 if (!should_prompt_for_signin_) { | 400 if (!should_prompt_for_signin_) { |
| 383 CompleteFunctionWithError(identity_constants::kUserNotSignedIn); | 401 CompleteFunctionWithError(identity_constants::kUserNotSignedIn); |
| 384 return true; | 402 return true; |
| 385 } | 403 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension()); | 505 const OAuth2Info& oauth2_info = OAuth2Info::GetOAuth2Info(extension()); |
| 488 IdentityAPI* id_api = IdentityAPI::GetFactoryInstance()->Get(GetProfile()); | 506 IdentityAPI* id_api = IdentityAPI::GetFactoryInstance()->Get(GetProfile()); |
| 489 IdentityTokenCacheValue cache_entry = id_api->GetCachedToken(*token_key_); | 507 IdentityTokenCacheValue cache_entry = id_api->GetCachedToken(*token_key_); |
| 490 IdentityTokenCacheValue::CacheValueStatus cache_status = | 508 IdentityTokenCacheValue::CacheValueStatus cache_status = |
| 491 cache_entry.status(); | 509 cache_entry.status(); |
| 492 | 510 |
| 493 if (type == IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE) { | 511 if (type == IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE) { |
| 494 switch (cache_status) { | 512 switch (cache_status) { |
| 495 case IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND: | 513 case IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND: |
| 496 #if defined(OS_CHROMEOS) | 514 #if defined(OS_CHROMEOS) |
| 497 // Always force minting token for ChromeOS kiosk app. | 515 // Always force minting token for ChromeOS kiosk app. |
|
Andrew T Wilson (Slow)
2015/09/29 13:20:30
Comment is out of date since we support public ses
kelvinp
2015/09/29 18:08:50
Done.
| |
| 498 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) { | 516 if (user_manager::UserManager::Get()->IsLoggedInAsPublicAccount() && |
| 517 !IsOriginWhitelistedInPublicSession()) { | |
| 518 CompleteFunctionWithError(identity_constants::kUserNotSignedIn); | |
| 519 return; | |
| 520 } | |
| 521 | |
| 522 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp() || | |
| 523 user_manager::UserManager::Get()->IsLoggedInAsPublicAccount()) { | |
| 499 gaia_mint_token_mode_ = OAuth2MintTokenFlow::MODE_MINT_TOKEN_FORCE; | 524 gaia_mint_token_mode_ = OAuth2MintTokenFlow::MODE_MINT_TOKEN_FORCE; |
| 500 policy::BrowserPolicyConnectorChromeOS* connector = | 525 policy::BrowserPolicyConnectorChromeOS* connector = |
| 501 g_browser_process->platform_part() | 526 g_browser_process->platform_part() |
| 502 ->browser_policy_connector_chromeos(); | 527 ->browser_policy_connector_chromeos(); |
| 503 if (connector->IsEnterpriseManaged()) { | 528 if (connector->IsEnterpriseManaged()) { |
| 504 StartDeviceLoginAccessTokenRequest(); | 529 StartDeviceLoginAccessTokenRequest(); |
| 505 } else { | 530 } else { |
| 506 StartLoginAccessTokenRequest(); | 531 StartLoginAccessTokenRequest(); |
| 507 } | 532 } |
| 508 return; | 533 return; |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 chromeos::DeviceOAuth2TokenServiceFactory::Get(); | 771 chromeos::DeviceOAuth2TokenServiceFactory::Get(); |
| 747 // Since robot account refresh tokens are scoped down to [any-api] only, | 772 // Since robot account refresh tokens are scoped down to [any-api] only, |
| 748 // request access token for [any-api] instead of login. | 773 // request access token for [any-api] instead of login. |
| 749 OAuth2TokenService::ScopeSet scopes; | 774 OAuth2TokenService::ScopeSet scopes; |
| 750 scopes.insert(GaiaConstants::kAnyApiOAuth2Scope); | 775 scopes.insert(GaiaConstants::kAnyApiOAuth2Scope); |
| 751 login_token_request_ = | 776 login_token_request_ = |
| 752 service->StartRequest(service->GetRobotAccountId(), | 777 service->StartRequest(service->GetRobotAccountId(), |
| 753 scopes, | 778 scopes, |
| 754 this); | 779 this); |
| 755 } | 780 } |
| 781 | |
| 782 bool IdentityGetAuthTokenFunction::IsOriginWhitelistedInPublicSession() { | |
| 783 for (unsigned int i = 0; i < arraysize(kPublicSessionAllowedOrigins); i++) { | |
|
Andrew T Wilson (Slow)
2015/09/29 13:20:30
nit: should i be size_t, not unsigned int? Also, w
kelvinp
2015/09/29 18:08:50
Good catch.
| |
| 784 URLPattern allowed_origin(URLPattern::SCHEME_ALL, | |
| 785 kPublicSessionAllowedOrigins[i]); | |
| 786 DCHECK(extension()); | |
|
Andrew T Wilson (Slow)
2015/09/29 13:20:30
Move this DCHECK outside the loop? And maybe also
kelvinp
2015/09/29 18:08:49
Done.
| |
| 787 if (allowed_origin.MatchesSecurityOrigin(extension()->url())) { | |
| 788 return true; | |
| 789 } | |
| 790 } | |
| 791 return false; | |
| 792 } | |
| 756 #endif | 793 #endif |
| 757 | 794 |
| 758 void IdentityGetAuthTokenFunction::StartLoginAccessTokenRequest() { | 795 void IdentityGetAuthTokenFunction::StartLoginAccessTokenRequest() { |
| 759 ProfileOAuth2TokenService* service = | 796 ProfileOAuth2TokenService* service = |
| 760 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); | 797 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); |
| 761 #if defined(OS_CHROMEOS) | 798 #if defined(OS_CHROMEOS) |
| 762 if (chrome::IsRunningInForcedAppMode()) { | 799 if (chrome::IsRunningInForcedAppMode()) { |
| 763 std::string app_client_id; | 800 std::string app_client_id; |
| 764 std::string app_client_secret; | 801 std::string app_client_secret; |
| 765 if (chromeos::UserSessionManager::GetInstance()-> | 802 if (chromeos::UserSessionManager::GetInstance()-> |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 969 if (redirect_url.GetWithEmptyPath() == final_url_prefix_) { | 1006 if (redirect_url.GetWithEmptyPath() == final_url_prefix_) { |
| 970 SetResult(new base::StringValue(redirect_url.spec())); | 1007 SetResult(new base::StringValue(redirect_url.spec())); |
| 971 SendResponse(true); | 1008 SendResponse(true); |
| 972 if (auth_flow_) | 1009 if (auth_flow_) |
| 973 auth_flow_.release()->DetachDelegateAndDelete(); | 1010 auth_flow_.release()->DetachDelegateAndDelete(); |
| 974 Release(); // Balanced in RunAsync. | 1011 Release(); // Balanced in RunAsync. |
| 975 } | 1012 } |
| 976 } | 1013 } |
| 977 | 1014 |
| 978 } // namespace extensions | 1015 } // namespace extensions |
| OLD | NEW |