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 // The list of apps that are allowed to use the Identity API to retrieve the | |
76 // token from the device robot account in a public session. | |
77 const char* const kPublicSessionAllowedOrigins[] = { | |
78 // Chrome Remote Desktop - Chromium branding. | |
79 "chrome-extension://ljacajndfccfgnfohlgkdphmbnpkjflk/", | |
80 // Chrome Remote Desktop - Official branding. | |
81 "chrome-extension://gbchcmhmhahfdphkhkmpfmihenigjmpp/"}; | |
82 | |
75 std::string GetPrimaryAccountId(content::BrowserContext* context) { | 83 std::string GetPrimaryAccountId(content::BrowserContext* context) { |
76 SigninManagerBase* signin_manager = | 84 SigninManagerBase* signin_manager = |
77 SigninManagerFactory::GetForProfile(Profile::FromBrowserContext(context)); | 85 SigninManagerFactory::GetForProfile(Profile::FromBrowserContext(context)); |
78 return signin_manager->GetAuthenticatedAccountId(); | 86 return signin_manager->GetAuthenticatedAccountId(); |
79 } | 87 } |
80 | 88 |
81 } // namespace | 89 } // namespace |
82 | 90 |
83 namespace identity = api::identity; | 91 namespace identity = api::identity; |
84 | 92 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 | 372 |
365 token_key_.reset( | 373 token_key_.reset( |
366 new ExtensionTokenKey(extension()->id(), account_key, scopes)); | 374 new ExtensionTokenKey(extension()->id(), account_key, scopes)); |
367 | 375 |
368 // From here on out, results must be returned asynchronously. | 376 // From here on out, results must be returned asynchronously. |
369 StartAsyncRun(); | 377 StartAsyncRun(); |
370 | 378 |
371 #if defined(OS_CHROMEOS) | 379 #if defined(OS_CHROMEOS) |
372 policy::BrowserPolicyConnectorChromeOS* connector = | 380 policy::BrowserPolicyConnectorChromeOS* connector = |
373 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 381 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
374 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp() && | 382 if ((user_manager::UserManager::Get()->IsLoggedInAsKioskApp() || |
383 IsOriginWhitelistedInPublicSession()) && | |
bartfab (slow)
2015/09/18 12:24:57
You should first check whether this is a public se
kelvinp
2015/09/22 00:50:37
Good point. IsOriginWhitelistedInPublicSession()
Michael Courage
2015/09/22 03:09:02
The Kiosk path is already kind of convoluted. It w
bartfab (slow)
2015/09/23 12:37:42
The order needs to be the opposite: Check whether
kelvinp
2015/09/23 21:08:54
I don't think there is a concern. For regular ses
| |
375 connector->IsEnterpriseManaged()) { | 384 connector->IsEnterpriseManaged()) { |
376 StartMintTokenFlow(IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE); | 385 StartMintTokenFlow(IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE); |
377 return true; | 386 return true; |
378 } | 387 } |
379 #endif | 388 #endif |
380 | 389 |
381 if (!HasLoginToken()) { | 390 if (!HasLoginToken()) { |
382 if (!should_prompt_for_signin_) { | 391 if (!should_prompt_for_signin_) { |
383 CompleteFunctionWithError(identity_constants::kUserNotSignedIn); | 392 CompleteFunctionWithError(identity_constants::kUserNotSignedIn); |
384 return true; | 393 return true; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 IdentityAPI* id_api = IdentityAPI::GetFactoryInstance()->Get(GetProfile()); | 497 IdentityAPI* id_api = IdentityAPI::GetFactoryInstance()->Get(GetProfile()); |
489 IdentityTokenCacheValue cache_entry = id_api->GetCachedToken(*token_key_); | 498 IdentityTokenCacheValue cache_entry = id_api->GetCachedToken(*token_key_); |
490 IdentityTokenCacheValue::CacheValueStatus cache_status = | 499 IdentityTokenCacheValue::CacheValueStatus cache_status = |
491 cache_entry.status(); | 500 cache_entry.status(); |
492 | 501 |
493 if (type == IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE) { | 502 if (type == IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE) { |
494 switch (cache_status) { | 503 switch (cache_status) { |
495 case IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND: | 504 case IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND: |
496 #if defined(OS_CHROMEOS) | 505 #if defined(OS_CHROMEOS) |
497 // Always force minting token for ChromeOS kiosk app. | 506 // Always force minting token for ChromeOS kiosk app. |
498 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) { | 507 if (user_manager::UserManager::Get()->IsLoggedInAsKioskApp() || |
508 IsOriginWhitelistedInPublicSession()) { | |
499 gaia_mint_token_mode_ = OAuth2MintTokenFlow::MODE_MINT_TOKEN_FORCE; | 509 gaia_mint_token_mode_ = OAuth2MintTokenFlow::MODE_MINT_TOKEN_FORCE; |
500 policy::BrowserPolicyConnectorChromeOS* connector = | 510 policy::BrowserPolicyConnectorChromeOS* connector = |
501 g_browser_process->platform_part() | 511 g_browser_process->platform_part() |
502 ->browser_policy_connector_chromeos(); | 512 ->browser_policy_connector_chromeos(); |
503 if (connector->IsEnterpriseManaged()) { | 513 if (connector->IsEnterpriseManaged()) { |
504 StartDeviceLoginAccessTokenRequest(); | 514 StartDeviceLoginAccessTokenRequest(); |
505 } else { | 515 } else { |
506 StartLoginAccessTokenRequest(); | 516 StartLoginAccessTokenRequest(); |
507 } | 517 } |
508 return; | 518 return; |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
746 chromeos::DeviceOAuth2TokenServiceFactory::Get(); | 756 chromeos::DeviceOAuth2TokenServiceFactory::Get(); |
747 // Since robot account refresh tokens are scoped down to [any-api] only, | 757 // Since robot account refresh tokens are scoped down to [any-api] only, |
748 // request access token for [any-api] instead of login. | 758 // request access token for [any-api] instead of login. |
749 OAuth2TokenService::ScopeSet scopes; | 759 OAuth2TokenService::ScopeSet scopes; |
750 scopes.insert(GaiaConstants::kAnyApiOAuth2Scope); | 760 scopes.insert(GaiaConstants::kAnyApiOAuth2Scope); |
751 login_token_request_ = | 761 login_token_request_ = |
752 service->StartRequest(service->GetRobotAccountId(), | 762 service->StartRequest(service->GetRobotAccountId(), |
753 scopes, | 763 scopes, |
754 this); | 764 this); |
755 } | 765 } |
766 | |
767 bool IdentityGetAuthTokenFunction::IsOriginWhitelistedInPublicSession() { | |
768 if (!user_manager::UserManager::Get()->IsLoggedInAsPublicAccount()) { | |
769 return false; | |
770 } | |
771 | |
772 for (unsigned int i = 0; i < arraysize(kPublicSessionAllowedOrigins); i++) { | |
773 URLPattern allowed_origin(URLPattern::SCHEME_ALL, | |
774 kPublicSessionAllowedOrigins[i]); | |
775 DCHECK(extension()); | |
776 if (allowed_origin.MatchesSecurityOrigin(extension()->url())) { | |
777 return true; | |
778 } | |
779 } | |
780 return false; | |
781 } | |
756 #endif | 782 #endif |
757 | 783 |
758 void IdentityGetAuthTokenFunction::StartLoginAccessTokenRequest() { | 784 void IdentityGetAuthTokenFunction::StartLoginAccessTokenRequest() { |
759 ProfileOAuth2TokenService* service = | 785 ProfileOAuth2TokenService* service = |
760 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); | 786 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); |
761 #if defined(OS_CHROMEOS) | 787 #if defined(OS_CHROMEOS) |
762 if (chrome::IsRunningInForcedAppMode()) { | 788 if (chrome::IsRunningInForcedAppMode()) { |
763 std::string app_client_id; | 789 std::string app_client_id; |
764 std::string app_client_secret; | 790 std::string app_client_secret; |
765 if (chromeos::UserSessionManager::GetInstance()-> | 791 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_) { | 995 if (redirect_url.GetWithEmptyPath() == final_url_prefix_) { |
970 SetResult(new base::StringValue(redirect_url.spec())); | 996 SetResult(new base::StringValue(redirect_url.spec())); |
971 SendResponse(true); | 997 SendResponse(true); |
972 if (auth_flow_) | 998 if (auth_flow_) |
973 auth_flow_.release()->DetachDelegateAndDelete(); | 999 auth_flow_.release()->DetachDelegateAndDelete(); |
974 Release(); // Balanced in RunAsync. | 1000 Release(); // Balanced in RunAsync. |
975 } | 1001 } |
976 } | 1002 } |
977 | 1003 |
978 } // namespace extensions | 1004 } // namespace extensions |
OLD | NEW |