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