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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 if (type == IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE) { | 212 if (type == IdentityMintRequestQueue::MINT_TYPE_NONINTERACTIVE) { |
213 switch (cache_status) { | 213 switch (cache_status) { |
214 case IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND: | 214 case IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND: |
215 #if defined(OS_CHROMEOS) | 215 #if defined(OS_CHROMEOS) |
216 // Always force minting token for ChromeOS kiosk app. | 216 // Always force minting token for ChromeOS kiosk app. |
217 if (chromeos::UserManager::Get()->IsLoggedInAsKioskApp()) { | 217 if (chromeos::UserManager::Get()->IsLoggedInAsKioskApp()) { |
218 if (g_browser_process->browser_policy_connector()-> | 218 if (g_browser_process->browser_policy_connector()-> |
219 IsEnterpriseManaged()) { | 219 IsEnterpriseManaged()) { |
220 OAuth2TokenService::ScopeSet scope_set(oauth2_info.scopes.begin(), | 220 OAuth2TokenService::ScopeSet scope_set(oauth2_info.scopes.begin(), |
221 oauth2_info.scopes.end()); | 221 oauth2_info.scopes.end()); |
| 222 chromeos::DeviceOAuth2TokenService* token_service = |
| 223 chromeos::DeviceOAuth2TokenServiceFactory::Get(); |
222 device_token_request_ = | 224 device_token_request_ = |
223 chromeos::DeviceOAuth2TokenServiceFactory::Get()->StartRequest( | 225 token_service->StartRequest(token_service->GetRobotAccountId(), |
224 scope_set, this); | 226 scope_set, |
| 227 this); |
225 } else { | 228 } else { |
226 gaia_mint_token_mode_ = OAuth2MintTokenFlow::MODE_MINT_TOKEN_FORCE; | 229 gaia_mint_token_mode_ = OAuth2MintTokenFlow::MODE_MINT_TOKEN_FORCE; |
227 StartLoginAccessTokenRequest(); | 230 StartLoginAccessTokenRequest(); |
228 } | 231 } |
229 return; | 232 return; |
230 } | 233 } |
231 #endif | 234 #endif |
232 | 235 |
233 if (oauth2_info.auto_approve) | 236 if (oauth2_info.auto_approve) |
234 // oauth2_info.auto_approve is protected by a whitelist in | 237 // oauth2_info.auto_approve is protected by a whitelist in |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 void IdentityGetAuthTokenFunction::StartLoginAccessTokenRequest() { | 420 void IdentityGetAuthTokenFunction::StartLoginAccessTokenRequest() { |
418 ProfileOAuth2TokenService* service = | 421 ProfileOAuth2TokenService* service = |
419 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()); | 422 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()); |
420 #if defined(OS_CHROMEOS) | 423 #if defined(OS_CHROMEOS) |
421 if (chrome::IsRunningInForcedAppMode()) { | 424 if (chrome::IsRunningInForcedAppMode()) { |
422 std::string app_client_id; | 425 std::string app_client_id; |
423 std::string app_client_secret; | 426 std::string app_client_secret; |
424 if (chromeos::UserManager::Get()->GetAppModeChromeClientOAuthInfo( | 427 if (chromeos::UserManager::Get()->GetAppModeChromeClientOAuthInfo( |
425 &app_client_id, &app_client_secret)) { | 428 &app_client_id, &app_client_secret)) { |
426 login_token_request_ = | 429 login_token_request_ = |
427 service->StartRequestForClient(app_client_id, | 430 service->StartRequestForClient(service->GetPrimaryAccountId(), |
| 431 app_client_id, |
428 app_client_secret, | 432 app_client_secret, |
429 OAuth2TokenService::ScopeSet(), | 433 OAuth2TokenService::ScopeSet(), |
430 this); | 434 this); |
431 return; | 435 return; |
432 } | 436 } |
433 } | 437 } |
434 #endif | 438 #endif |
435 login_token_request_ = service->StartRequest(OAuth2TokenService::ScopeSet(), | 439 login_token_request_ = service->StartRequest( |
436 this); | 440 service->GetPrimaryAccountId(), OAuth2TokenService::ScopeSet(), this); |
437 } | 441 } |
438 | 442 |
439 void IdentityGetAuthTokenFunction::StartGaiaRequest( | 443 void IdentityGetAuthTokenFunction::StartGaiaRequest( |
440 const std::string& login_access_token) { | 444 const std::string& login_access_token) { |
441 DCHECK(!login_access_token.empty()); | 445 DCHECK(!login_access_token.empty()); |
442 mint_token_flow_.reset(CreateMintTokenFlow(login_access_token)); | 446 mint_token_flow_.reset(CreateMintTokenFlow(login_access_token)); |
443 mint_token_flow_->Start(); | 447 mint_token_flow_->Start(); |
444 } | 448 } |
445 | 449 |
446 void IdentityGetAuthTokenFunction::ShowLoginPopup() { | 450 void IdentityGetAuthTokenFunction::ShowLoginPopup() { |
(...skipping 23 matching lines...) Expand all Loading... |
470 OAuth2MintTokenFlow::Parameters( | 474 OAuth2MintTokenFlow::Parameters( |
471 login_access_token, | 475 login_access_token, |
472 GetExtension()->id(), | 476 GetExtension()->id(), |
473 oauth2_client_id_, | 477 oauth2_client_id_, |
474 oauth2_info.scopes, | 478 oauth2_info.scopes, |
475 gaia_mint_token_mode_)); | 479 gaia_mint_token_mode_)); |
476 return mint_token_flow; | 480 return mint_token_flow; |
477 } | 481 } |
478 | 482 |
479 bool IdentityGetAuthTokenFunction::HasLoginToken() const { | 483 bool IdentityGetAuthTokenFunction::HasLoginToken() const { |
480 return ProfileOAuth2TokenServiceFactory::GetForProfile(profile())-> | 484 ProfileOAuth2TokenService* token_service = |
481 RefreshTokenIsAvailable(); | 485 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()); |
| 486 return token_service->RefreshTokenIsAvailable( |
| 487 token_service->GetPrimaryAccountId()); |
482 } | 488 } |
483 | 489 |
484 std::string IdentityGetAuthTokenFunction::MapOAuth2ErrorToDescription( | 490 std::string IdentityGetAuthTokenFunction::MapOAuth2ErrorToDescription( |
485 const std::string& error) { | 491 const std::string& error) { |
486 const char kOAuth2ErrorAccessDenied[] = "access_denied"; | 492 const char kOAuth2ErrorAccessDenied[] = "access_denied"; |
487 const char kOAuth2ErrorInvalidScope[] = "invalid_scope"; | 493 const char kOAuth2ErrorInvalidScope[] = "invalid_scope"; |
488 | 494 |
489 if (error == kOAuth2ErrorAccessDenied) | 495 if (error == kOAuth2ErrorAccessDenied) |
490 return std::string(identity_constants::kUserRejected); | 496 return std::string(identity_constants::kUserRejected); |
491 else if (error == kOAuth2ErrorInvalidScope) | 497 else if (error == kOAuth2ErrorInvalidScope) |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 const IdentityAPI::TokenCacheKey& rhs) const { | 774 const IdentityAPI::TokenCacheKey& rhs) const { |
769 if (extension_id < rhs.extension_id) | 775 if (extension_id < rhs.extension_id) |
770 return true; | 776 return true; |
771 else if (rhs.extension_id < extension_id) | 777 else if (rhs.extension_id < extension_id) |
772 return false; | 778 return false; |
773 | 779 |
774 return scopes < rhs.scopes; | 780 return scopes < rhs.scopes; |
775 } | 781 } |
776 | 782 |
777 } // namespace extensions | 783 } // namespace extensions |
OLD | NEW |