Index: chrome/browser/signin/token_service.cc |
=================================================================== |
--- chrome/browser/signin/token_service.cc (revision 177312) |
+++ chrome/browser/signin/token_service.cc (working copy) |
@@ -103,6 +103,15 @@ |
token_map_[service] = auth_token; |
FireTokenAvailableNotification(service, auth_token); |
SaveAuthTokenToDB(service, auth_token); |
+ |
+#if defined(OS_CHROMEOS) |
+ // We don't ever want to fetch OAuth2 tokens from LSO service token in case |
+ // when ChromeOS is in forced OAuth2 use mode. OAuth2 token should only |
+ // arrive into token service exclusively through UpdateCredentialsWithOAuth2. |
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kForceOAuth1)) |
+ return; |
+#endif |
+ |
// If we got ClientLogin token for "lso" service, and we don't already have |
// OAuth2 tokens, start fetching OAuth2 login scoped token pair. |
if (service == GaiaConstants::kLSOService && !HasOAuthLoginToken()) { |
@@ -147,10 +156,8 @@ |
} |
void TokenService::UpdateCredentialsWithOAuth2( |
- const GaiaAuthConsumer::ClientOAuthResult& credentials) { |
- // Will be implemented once the ClientOAuth signin is complete. Not called |
- // yet by any code. |
- NOTREACHED(); |
+ const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) { |
+ SaveOAuth2Credentials(oauth2_tokens); |
} |
void TokenService::LoadTokensFromDB() { |
@@ -232,6 +239,10 @@ |
return HasTokenForService(GaiaConstants::kGaiaOAuth2LoginRefreshToken); |
} |
+bool TokenService::HasOAuthLoginAccessToken() const { |
+ return HasTokenForService(GaiaConstants::kGaiaOAuth2LoginAccessToken); |
+} |
+ |
const std::string& TokenService::GetOAuth2LoginRefreshToken() const { |
return GetTokenForService(GaiaConstants::kGaiaOAuth2LoginRefreshToken); |
} |
@@ -312,13 +323,16 @@ |
void TokenService::OnClientOAuthSuccess(const ClientOAuthResult& result) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
VLOG(1) << "Got OAuth2 login token pair"; |
+ SaveOAuth2Credentials(result); |
+} |
+ |
+void TokenService::SaveOAuth2Credentials(const ClientOAuthResult& result) { |
token_map_[GaiaConstants::kGaiaOAuth2LoginRefreshToken] = |
result.refresh_token; |
token_map_[GaiaConstants::kGaiaOAuth2LoginAccessToken] = result.access_token; |
+ // Save refresh token only since access token is transient anyway. |
SaveAuthTokenToDB(GaiaConstants::kGaiaOAuth2LoginRefreshToken, |
result.refresh_token); |
- SaveAuthTokenToDB(GaiaConstants::kGaiaOAuth2LoginAccessToken, |
- result.access_token); |
// We don't save expiration information for now. |
FireTokenAvailableNotification(GaiaConstants::kGaiaOAuth2LoginRefreshToken, |