summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-01 03:02:10 +0000
committerzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-01 03:02:10 +0000
commit98c7147a5a92b9c9ef0069c49a33eed8133ed812 (patch)
tree769c72524d0a9af1dc73cebc234d7e1a835b4d6f
parentd523467f140d3676c8d2598897b4829ef9d1a348 (diff)
downloadchromium_src-98c7147a5a92b9c9ef0069c49a33eed8133ed812.zip
chromium_src-98c7147a5a92b9c9ef0069c49a33eed8133ed812.tar.gz
chromium_src-98c7147a5a92b9c9ef0069c49a33eed8133ed812.tar.bz2
Passed app-specific client id and secret to OAuth2TokenService
BUG=266183 TEST=kiosk tests Review URL: https://chromiumcodereview.appspot.com/21164006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214934 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/api/identity/experimental_identity_api.cc33
-rw-r--r--chrome/browser/extensions/api/identity/identity_api.cc33
-rw-r--r--chrome/browser/signin/oauth2_token_service.cc70
-rw-r--r--chrome/browser/signin/oauth2_token_service.h19
-rw-r--r--google_apis/gaia/oauth2_api_call_flow.cc16
-rw-r--r--google_apis/gaia/oauth2_api_call_flow.h9
6 files changed, 123 insertions, 57 deletions
diff --git a/chrome/browser/extensions/api/identity/experimental_identity_api.cc b/chrome/browser/extensions/api/identity/experimental_identity_api.cc
index 27c5051..2e01c4e 100644
--- a/chrome/browser/extensions/api/identity/experimental_identity_api.cc
+++ b/chrome/browser/extensions/api/identity/experimental_identity_api.cc
@@ -227,9 +227,25 @@ void ExperimentalIdentityGetAuthTokenFunction::OnGetTokenFailure(
}
void ExperimentalIdentityGetAuthTokenFunction::StartLoginAccessTokenRequest() {
- login_token_request_ =
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile())->
- StartRequest(OAuth2TokenService::ScopeSet(), this);
+ ProfileOAuth2TokenService* service =
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
+#if defined(OS_CHROMEOS)
+ if (chrome::IsRunningInForcedAppMode()) {
+ std::string app_client_id;
+ std::string app_client_secret;
+ if (chromeos::UserManager::Get()->GetAppModeChromeClientOAuthInfo(
+ &app_client_id, &app_client_secret)) {
+ login_token_request_ =
+ service->StartRequestForClient(app_client_id,
+ app_client_secret,
+ OAuth2TokenService::ScopeSet(),
+ this);
+ return;
+ }
+ }
+#endif
+ login_token_request_ = service->StartRequest(OAuth2TokenService::ScopeSet(),
+ this);
}
void ExperimentalIdentityGetAuthTokenFunction::StartGaiaRequest(
@@ -269,17 +285,6 @@ ExperimentalIdentityGetAuthTokenFunction::CreateMintTokenFlow(
oauth2_info.client_id,
oauth2_info.scopes,
gaia_mint_token_mode_));
-#if defined(OS_CHROMEOS)
- if (chrome::IsRunningInForcedAppMode()) {
- std::string chrome_client_id;
- std::string chrome_client_secret;
- if (chromeos::UserManager::Get()->GetAppModeChromeClientOAuthInfo(
- &chrome_client_id, &chrome_client_secret)) {
- mint_token_flow->SetChromeOAuthClientInfo(chrome_client_id,
- chrome_client_secret);
- }
- }
-#endif
return mint_token_flow;
}
diff --git a/chrome/browser/extensions/api/identity/identity_api.cc b/chrome/browser/extensions/api/identity/identity_api.cc
index 75dcaba..6a8beb7 100644
--- a/chrome/browser/extensions/api/identity/identity_api.cc
+++ b/chrome/browser/extensions/api/identity/identity_api.cc
@@ -416,9 +416,25 @@ void IdentityGetAuthTokenFunction::OnGetTokenFailure(
}
void IdentityGetAuthTokenFunction::StartLoginAccessTokenRequest() {
- login_token_request_ =
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile())->
- StartRequest(OAuth2TokenService::ScopeSet(), this);
+ ProfileOAuth2TokenService* service =
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
+#if defined(OS_CHROMEOS)
+ if (chrome::IsRunningInForcedAppMode()) {
+ std::string app_client_id;
+ std::string app_client_secret;
+ if (chromeos::UserManager::Get()->GetAppModeChromeClientOAuthInfo(
+ &app_client_id, &app_client_secret)) {
+ login_token_request_ =
+ service->StartRequestForClient(app_client_id,
+ app_client_secret,
+ OAuth2TokenService::ScopeSet(),
+ this);
+ return;
+ }
+ }
+#endif
+ login_token_request_ = service->StartRequest(OAuth2TokenService::ScopeSet(),
+ this);
}
void IdentityGetAuthTokenFunction::StartGaiaRequest(
@@ -458,17 +474,6 @@ OAuth2MintTokenFlow* IdentityGetAuthTokenFunction::CreateMintTokenFlow(
oauth2_client_id_,
oauth2_info.scopes,
gaia_mint_token_mode_));
-#if defined(OS_CHROMEOS)
- if (chrome::IsRunningInForcedAppMode()) {
- std::string chrome_client_id;
- std::string chrome_client_secret;
- if (chromeos::UserManager::Get()->GetAppModeChromeClientOAuthInfo(
- &chrome_client_id, &chrome_client_secret)) {
- mint_token_flow->SetChromeOAuthClientInfo(chrome_client_id,
- chrome_client_secret);
- }
- }
-#endif
return mint_token_flow;
}
diff --git a/chrome/browser/signin/oauth2_token_service.cc b/chrome/browser/signin/oauth2_token_service.cc
index 9569625..0b6bd5d 100644
--- a/chrome/browser/signin/oauth2_token_service.cc
+++ b/chrome/browser/signin/oauth2_token_service.cc
@@ -77,6 +77,8 @@ class OAuth2TokenService::Fetcher : public OAuth2AccessTokenConsumer {
// The given |oauth2_token_service| will be informed when fetching is done.
static Fetcher* CreateAndStart(OAuth2TokenService* oauth2_token_service,
net::URLRequestContextGetter* getter,
+ const std::string& chrome_client_id,
+ const std::string& chrome_client_secret,
const std::string& refresh_token,
const OAuth2TokenService::ScopeSet& scopes,
base::WeakPtr<RequestImpl> waiting_request);
@@ -102,6 +104,8 @@ class OAuth2TokenService::Fetcher : public OAuth2AccessTokenConsumer {
private:
Fetcher(OAuth2TokenService* oauth2_token_service,
net::URLRequestContextGetter* getter,
+ const std::string& chrome_client_id,
+ const std::string& chrome_client_secret,
const std::string& refresh_token,
const OAuth2TokenService::ScopeSet& scopes,
base::WeakPtr<RequestImpl> waiting_request);
@@ -131,6 +135,9 @@ class OAuth2TokenService::Fetcher : public OAuth2AccessTokenConsumer {
GoogleServiceAuthError error_;
std::string access_token_;
base::Time expiration_date_;
+ // OAuth2 client id and secret.
+ std::string chrome_client_id_;
+ std::string chrome_client_secret_;
DISALLOW_COPY_AND_ASSIGN(Fetcher);
};
@@ -139,11 +146,19 @@ class OAuth2TokenService::Fetcher : public OAuth2AccessTokenConsumer {
OAuth2TokenService::Fetcher* OAuth2TokenService::Fetcher::CreateAndStart(
OAuth2TokenService* oauth2_token_service,
net::URLRequestContextGetter* getter,
+ const std::string& chrome_client_id,
+ const std::string& chrome_client_secret,
const std::string& refresh_token,
const OAuth2TokenService::ScopeSet& scopes,
base::WeakPtr<RequestImpl> waiting_request) {
OAuth2TokenService::Fetcher* fetcher = new Fetcher(
- oauth2_token_service, getter, refresh_token, scopes, waiting_request);
+ oauth2_token_service,
+ getter,
+ chrome_client_id,
+ chrome_client_secret,
+ refresh_token,
+ scopes,
+ waiting_request);
fetcher->Start();
return fetcher;
}
@@ -151,6 +166,8 @@ OAuth2TokenService::Fetcher* OAuth2TokenService::Fetcher::CreateAndStart(
OAuth2TokenService::Fetcher::Fetcher(
OAuth2TokenService* oauth2_token_service,
net::URLRequestContextGetter* getter,
+ const std::string& chrome_client_id,
+ const std::string& chrome_client_secret,
const std::string& refresh_token,
const OAuth2TokenService::ScopeSet& scopes,
base::WeakPtr<RequestImpl> waiting_request)
@@ -159,7 +176,9 @@ OAuth2TokenService::Fetcher::Fetcher(
refresh_token_(refresh_token),
scopes_(scopes),
retry_number_(0),
- error_(GoogleServiceAuthError::SERVICE_UNAVAILABLE) {
+ error_(GoogleServiceAuthError::SERVICE_UNAVAILABLE),
+ chrome_client_id_(chrome_client_id),
+ chrome_client_secret_(chrome_client_secret) {
DCHECK(oauth2_token_service_);
DCHECK(getter_.get());
DCHECK(refresh_token_.length());
@@ -174,8 +193,8 @@ OAuth2TokenService::Fetcher::~Fetcher() {
void OAuth2TokenService::Fetcher::Start() {
fetcher_.reset(new OAuth2AccessTokenFetcher(this, getter_.get()));
- fetcher_->Start(GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
- GaiaUrls::GetInstance()->oauth2_chrome_client_secret(),
+ fetcher_->Start(chrome_client_id_,
+ chrome_client_secret_,
refresh_token_,
std::vector<std::string>(scopes_.begin(), scopes_.end()));
retry_timer_.Stop();
@@ -318,7 +337,26 @@ bool OAuth2TokenService::RefreshTokenIsAvailable() {
scoped_ptr<OAuth2TokenService::Request> OAuth2TokenService::StartRequest(
const OAuth2TokenService::ScopeSet& scopes,
OAuth2TokenService::Consumer* consumer) {
- return StartRequestWithContext(GetRequestContext(), scopes, consumer);
+ return StartRequestForClientWithContext(
+ GetRequestContext(),
+ GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
+ GaiaUrls::GetInstance()->oauth2_chrome_client_secret(),
+ scopes,
+ consumer);
+}
+
+scoped_ptr<OAuth2TokenService::Request>
+OAuth2TokenService::StartRequestForClient(
+ const std::string& client_id,
+ const std::string& client_secret,
+ const OAuth2TokenService::ScopeSet& scopes,
+ OAuth2TokenService::Consumer* consumer) {
+ return StartRequestForClientWithContext(
+ GetRequestContext(),
+ client_id,
+ client_secret,
+ scopes,
+ consumer);
}
scoped_ptr<OAuth2TokenService::Request>
@@ -326,6 +364,21 @@ OAuth2TokenService::StartRequestWithContext(
net::URLRequestContextGetter* getter,
const ScopeSet& scopes,
Consumer* consumer) {
+ return StartRequestForClientWithContext(
+ getter,
+ GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
+ GaiaUrls::GetInstance()->oauth2_chrome_client_secret(),
+ scopes,
+ consumer);
+}
+
+scoped_ptr<OAuth2TokenService::Request>
+OAuth2TokenService::StartRequestForClientWithContext(
+ net::URLRequestContextGetter* getter,
+ const std::string& client_id,
+ const std::string& client_secret,
+ const ScopeSet& scopes,
+ Consumer* consumer) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
scoped_ptr<RequestImpl> request(new RequestImpl(consumer));
@@ -357,7 +410,12 @@ OAuth2TokenService::StartRequestWithContext(
}
pending_fetchers_[fetch_parameters] =
- Fetcher::CreateAndStart(this, getter, refresh_token, scopes,
+ Fetcher::CreateAndStart(this,
+ getter,
+ client_id,
+ client_secret,
+ refresh_token,
+ scopes,
request->AsWeakPtr());
return request.PassAs<Request>();
}
diff --git a/chrome/browser/signin/oauth2_token_service.h b/chrome/browser/signin/oauth2_token_service.h
index ac3451d..d63fbdf 100644
--- a/chrome/browser/signin/oauth2_token_service.h
+++ b/chrome/browser/signin/oauth2_token_service.h
@@ -117,6 +117,15 @@ class OAuth2TokenService {
virtual scoped_ptr<Request> StartRequest(const ScopeSet& scopes,
Consumer* consumer);
+ // This method does the same as |StartRequest| except it uses |client_id| and
+ // |client_secret| to identify OAuth client app instead of using
+ // Chrome's default values.
+ virtual scoped_ptr<Request> StartRequestForClient(
+ const std::string& client_id,
+ const std::string& client_secret,
+ const ScopeSet& scopes,
+ Consumer* consumer);
+
// This method does the same as |StartRequest| except it uses the request
// context given by |getter| instead of using the one returned by
// |GetRequestContext| implemented by derived classes.
@@ -217,6 +226,16 @@ class OAuth2TokenService {
base::Time expiration_date;
};
+ // This method does the same as |StartRequestWithContext| except it
+ // uses |client_id| and |client_secret| to identify OAuth
+ // client app instead of using Chrome's default values.
+ scoped_ptr<Request> StartRequestForClientWithContext(
+ net::URLRequestContextGetter* getter,
+ const std::string& client_id,
+ const std::string& client_secret,
+ const ScopeSet& scopes,
+ Consumer* consumer);
+
// Returns a currently valid OAuth2 access token for the given set of scopes,
// or NULL if none have been cached. Note the user of this method should
// ensure no entry with the same |scopes| is added before the usage of the
diff --git a/google_apis/gaia/oauth2_api_call_flow.cc b/google_apis/gaia/oauth2_api_call_flow.cc
index 9f24b18..4c4940d 100644
--- a/google_apis/gaia/oauth2_api_call_flow.cc
+++ b/google_apis/gaia/oauth2_api_call_flow.cc
@@ -41,9 +41,6 @@ OAuth2ApiCallFlow::OAuth2ApiCallFlow(
refresh_token_(refresh_token),
access_token_(access_token),
scopes_(scopes),
- chrome_client_id_(GaiaUrls::GetInstance()->oauth2_chrome_client_id()),
- chrome_client_secret_(
- GaiaUrls::GetInstance()->oauth2_chrome_client_secret()),
state_(INITIAL),
tried_mint_access_token_(false) {
}
@@ -54,15 +51,6 @@ void OAuth2ApiCallFlow::Start() {
BeginApiCall();
}
-#if defined(OS_CHROMEOS)
-void OAuth2ApiCallFlow::SetChromeOAuthClientInfo(
- const std::string& chrome_client_id,
- const std::string& chrome_client_secret) {
- chrome_client_id_ = chrome_client_id;
- chrome_client_secret_ = chrome_client_secret;
-}
-#endif
-
void OAuth2ApiCallFlow::BeginApiCall() {
CHECK(state_ == INITIAL || state_ == MINT_ACCESS_TOKEN_DONE);
@@ -118,8 +106,8 @@ void OAuth2ApiCallFlow::BeginMintAccessToken() {
oauth2_access_token_fetcher_.reset(CreateAccessTokenFetcher());
oauth2_access_token_fetcher_->Start(
- chrome_client_id_,
- chrome_client_secret_,
+ GaiaUrls::GetInstance()->oauth2_chrome_client_id(),
+ GaiaUrls::GetInstance()->oauth2_chrome_client_secret(),
refresh_token_,
scopes_);
}
diff --git a/google_apis/gaia/oauth2_api_call_flow.h b/google_apis/gaia/oauth2_api_call_flow.h
index fa7dd5c..fccd1e7 100644
--- a/google_apis/gaia/oauth2_api_call_flow.h
+++ b/google_apis/gaia/oauth2_api_call_flow.h
@@ -50,11 +50,6 @@ class OAuth2ApiCallFlow
// Start the flow.
virtual void Start();
-#if defined(OS_CHROMEOS)
- void SetChromeOAuthClientInfo(const std::string& chrome_client_id,
- const std::string& chrome_client_secret);
-#endif
-
// OAuth2AccessTokenFetcher implementation.
virtual void OnGetTokenSuccess(const std::string& access_token,
const base::Time& expiration_time) OVERRIDE;
@@ -118,10 +113,6 @@ class OAuth2ApiCallFlow
std::string access_token_;
std::vector<std::string> scopes_;
- // Override values for the main chrome client id and secret.
- std::string chrome_client_id_;
- std::string chrome_client_secret_;
-
State state_;
// Whether we have already tried minting an access token once.
bool tried_mint_access_token_;